How would one proceed to plot this?

1 view (last 30 days)
Frederick Melanson
Frederick Melanson on 22 Sep 2020
Commented: Dana on 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!

Answers (1)

Dana on 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;
Dana on 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;
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:
hold on

Sign in to comment.


Find more on Line Plots in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!