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

6 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Price 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