# How would one proceed to plot this?

2 ビュー (過去 30 日間)
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 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 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 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 Center および File ExchangeTwo y-axis についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by