How would one proceed to plot this?

조회 수: 2 (최근 30일)
Frederick Melanson
Frederick Melanson 2020년 9월 22일
댓글: Dana 2020년 9월 22일
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!

답변 (1개)

Dana
Dana 2020년 9월 22일
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
Frederick Melanson
Frederick Melanson 2020년 9월 22일
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 2020년 9월 22일
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))

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by