why I'm getting error with symsum?

2 次查看(过去 30 天)
I have tried this code to calculate energy and power of discrete time functions. but I get errors. how can I fix it?
syms n f z N;
f=input('enter function: ','s');
f = symfun(eval(f), n);
f=f*conj(f);
f = matlabFunction(f);
y(N)=symsum(f, -N , N);
energy=limit(y(N),N,inf);
z(N)=y(N)/(2*N+1);
pow=limit(z(N),N,inf);
  9 个评论
geometry geometry
geometry geometry 2018-3-19
编辑:geometry geometry 2018-3-19
I changed the code and tried without symsum and using "for" but again I get a lot of errors:
syms f n y x Z p s H i E P
E=0;
P=0;
H(n)=heaviside(n)+(1/2)*piecewise(n==0,1,0);
%x(n)=piecewise(n==0,1,0)+piecewise(n==4,1,0)-2*heaviside(n+3)+2*heaviside(n-3);
%Z(n)=(-1)^(n)*cos(n*pi/2)*x(n);
f=input('enter function: ');
f=f*conj(f);
f = matlabFunction(f);
for i=-N:N
E=E+f(i);
end
P(N)=E/(2*N+1);
E=limit(E(N),N,inf);
P=limit(P(N),N,inf);
when I enter x(n) and z(n) (which are commented in the code).
Walter Roberson
Walter Roberson 2018-3-19
You did not use the 'file' option of matlabFunction .
You have
for i=-N:N
but you have not defined N .
Your later line E=limit(E(N),N,inf); would expect N to be sym, but it is not permitted to have a for loop over symbolic range.
Note: you should probably be replacing your heaviside with piecewise, as heaviside has ambiguous meaning at 0.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numbers and Precision 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by