How would one proceed to plot this?

2 Ansichten (letzte 30 Tage)
Frederick Melanson
Frederick Melanson am 22 Sep. 2020
Kommentiert: Dana am 22 Sep. 2020
I would like to plot this:
y[n]=3/40*(-3/4)^n*u[n]+1/20*(1/2)^n*u[n] for -2<=n<=100
im not sure how to proceed with the u[n] function and the for loop
Thank you!

Antworten (1)

Dana
Dana am 22 Sep. 2020
What is u supposed to be? Some kind of vector you've previously defined? If so, and assuming u is a column vector whose j-th element corresponds to n=j-3 (e.g., the first element of u corresponds to n=1-3=-2, etc.):
nvc = (-2:100).';
y = 3/40*(-3/4).^n.*u + 1/20*(1/2).^n.*u;
figure
plot(nvc,y)
  2 Kommentare
Frederick Melanson
Frederick Melanson am 22 Sep. 2020
its a sigal with the function and we are simulating it from -2 to 100 where u[n] is the unit step impluse
Dana
Dana am 22 Sep. 2020
I see, so you haven't actually defined u in your program anywhere, but in principle it's the Heaviside function, yes?
In that case, as I now understand it, you don't want to plot the value of y only for integer values of n (which is what I previously understood). In that case, you need to pick a "resolution" (i.e., the interval between successive values of n that you'll plot). Then:
res = 0.01; % resolution parameter
n = (-2:res:100).'; % vector of values of n from -2 to 100 spaced res apart
u = (n>=0); % Heaviside function; vector with 0 (false) if corresponding
% element of n is <0, 1 (true) if >0.
y = 3/40*(-3/4).^n.*u + 1/20*(1/2).^n.*u;
figure
plot(nvc,y)
In terms of the plot, this will plot things continuously. If instead you want to see the discontinuity at n=0, you can instead plot n<0 and n>=0 ranges separately:
figure
hold on
plot(nvc(~u),y(~u))
plot(nvc(u),y(u))

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by