how can I write a function y(n) in terms of function x(n)?

5 ビュー (過去 30 日間)
geometry geometry
geometry geometry 2018 年 3 月 17 日
編集済み: Walter Roberson 2018 年 3 月 17 日
I run this code and I get error. (the error is for function y which contains function x in its defenition). how can i fix this error? (The functions x and y are discrete signals)
syms n y x
n=-10:1:10;
x=dirac(n+1)+dirac(-n+4)-2*heaviside(n+3);
y(n)=x(n)-x(2*n+3);
plot(x,'o');
plot(y,'o');

採用された回答

Walter Roberson
Walter Roberson 2018 年 3 月 17 日
syms n y x
x(n) = dirac(n+1)+dirac(-n+4)-2*heaviside(n+3);
y(n) = x(n)-x(2*n+3);
N=-10:1:10;
plot(N, subs(x,n,N), 'ko', N, subs(y,n,N), 'bo')
It will not look like much, since dirac() is only ever 0 or infinity.
  4 件のコメント
Walter Roberson
Walter Roberson 2018 年 3 月 17 日
Calls of the form
plot(x1, y1, x2, y2)
are the same as
ax = gca;
curhold = get(ax, 'NextPlot');
plot(ax, x1, y1);
set(gca, 'NextPlot', 'add')
plot(x2, y2);
set(ax, 'NextPlot', curhold)
That is, passing multiple x, y pairs into plot() causes both lines to be plotted.
So the N, subs(x,n,N) part causes x to be plotted, and the N, subs(y,n,N) causes y to be plotted.
This might have given you the impression that y was not plotted because the y values consist only of 0s and infinities.
Walter Roberson
Walter Roberson 2018 年 3 月 17 日
編集済み: Walter Roberson 2018 年 3 月 17 日
"which function should I use for discrete dirac signals? (i.e the function that is only one in time zero)"
You can use
Dirac = @(x) not(x)
if you can be certain that none of the values are nan. If nan is a possibility then use
Dirac = @(x) x == 0;
However, if you are working with symbolic values, then you need
Dirac = @(x) piecewise(x == 0, 1, 0)

サインインしてコメントする。

その他の回答 (1 件)

elham kreem
elham kreem 2018 年 3 月 17 日
if you run x , it is a vector 1x21 , then when you used for y(n) , you will get for x a subscript more
than 21 ,such as if you have n=10 then you have x(23) , and this is not found.the result, it is not run

カテゴリ

Help Center および File ExchangePrice and Analyze Financial Instruments についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by