why I'm getting error with symsum?

3 ビュー (過去 30 日間)
geometry geometry
geometry geometry 2018 年 3 月 19 日
コメント済み: Walter Roberson 2018 年 3 月 19 日
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 Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by