How Do You Plot a Cosine Function with a Unit Step in MATLAB?

Click For Summary
To plot the function cos(pi*n)*u(n) in MATLAB, the unit step function u(n) is defined as y=(n>=0), which ensures the function is only evaluated for non-negative n. The code snippet provided initializes n from 0 to 10 and computes x using x(n) = cos(pi*n)*y. A user suggests using a continuous time variable t from -2 to 2, setting x=cos(pi*t) and zeroing out values for t<=0 to apply the unit step function. The discussion clarifies the implementation of the unit step function in the context of plotting the cosine function. Understanding the role of u(t) in the equation is essential for accurate plotting.
cleopatra
Messages
45
Reaction score
0

Homework Statement



plot this function:
cos(pi*n)*u(n)



The Attempt at a Solution



n=0:1:10;
y=(n>=0);

x(n) = cos(pi()*n)*y

figure(1)
plot(y)
 
Physics news on Phys.org
cleopatra said:

Homework Statement



plot this function:
cos(pi*n)*u(n)

The Attempt at a Solution



n=0:1:10;
y=(n>=0);

x(n) = cos(pi()*n)*y

figure(1)
plot(y)

y(t>=0)=1; ?

This should work ..
t=-2:0.1:2;
x=cos(pi()*t); x(t<=0)=0;
plot(t,x);
 
Last edited:
I don´t get what x(t<=0)=0 does ?
And where do you multiply the unit step function?
You wrote x=cos(pi()*t); but I can´t see where u(t) is...
 
nevermind I got it. thanks
 
Question: A clock's minute hand has length 4 and its hour hand has length 3. What is the distance between the tips at the moment when it is increasing most rapidly?(Putnam Exam Question) Answer: Making assumption that both the hands moves at constant angular velocities, the answer is ## \sqrt{7} .## But don't you think this assumption is somewhat doubtful and wrong?

Similar threads

  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 14 ·
Replies
14
Views
2K
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
Replies
3
Views
2K
  • · Replies 40 ·
2
Replies
40
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K