why I'm getting error with symsum?
古いコメントを表示
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 件のコメント
Walter Roberson
2018 年 3 月 19 日
Why are you using eval() for that code??
If you are going to use eval() then why not just use input() without the 's' option?
geometry geometry
2018 年 3 月 19 日
Walter Roberson
2018 年 3 月 19 日
What function are you entering?
geometry geometry
2018 年 3 月 19 日
Walter Roberson
2018 年 3 月 19 日
... Yes?
1/n is expected to have a problem since you have n pass through 0.
limit() seldom knows how to take the limit of a symsum.
geometry geometry
2018 年 3 月 19 日
Walter Roberson
2018 年 3 月 19 日
Use the 'file' option of matlabFunction. The .m that is written will use if to implement the piecewise(). Note, however, that the result will not be vectorized
Note: you should not be using symsum() on a function handle. symsum() should only be executed on a symbolic expression.
symsum() is not very good at reasoning about dirac and heaviside
geometry geometry
2018 年 3 月 19 日
編集済み: geometry geometry
2018 年 3 月 19 日
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 件)
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!