Filter löschen
Filter löschen

why I'm getting error with symsum?

2 Ansichten (letzte 30 Tage)
geometry geometry
geometry geometry am 19 Mär. 2018
Kommentiert: Walter Roberson am 19 Mär. 2018
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 Kommentare
geometry geometry
geometry geometry am 19 Mär. 2018
Bearbeitet: geometry geometry am 19 Mär. 2018
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 am 19 Mär. 2018
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by