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

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 19K views
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