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 CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by