How to use symsum function inside a function
13 ビュー (過去 30 日間)
古いコメントを表示
Chandra Sekhar Kommineni
2022 年 1 月 9 日
Below I'm trying to write a small function, but I'm getting following error message
Unable to create a symbolic variable 'j' by using 'syms' inside a MATLAB function because 'j' is an existing function name, class name, method name, and so on. Use 'sym' instead.
the code is working outside the function module, I don't know the exact reason behind this? could someone explain me how to rectify this?
Thank yyou so much in advance
function [Area sigma]= Fractalblock(L0,t0,Rt,N,T);
syms j
Area= (L0*t0*symsum((4^(j+1))*((0.5)^j)*(Rt^j),j,0,N-1))-((t0^2)*symsum(2^(2*j+1)*(Rt^((2*j)-1)),j,1,N-1))-((t0^2)*symsum(2^(2*j+2)*Rt^(2*j),j,0,N-1));
sigma= area/T^2;
end
0 件のコメント
採用された回答
Walter Roberson
2022 年 1 月 9 日
I have not seen that message before, but the work-around is
function [Area sigma]= Fractalblock(L0,t0,Rt,N,T);
j = sym('j');
Area= (L0*t0*symsum((4^(j+1))*((0.5)^j)*(Rt^j),j,0,N-1))-((t0^2)*symsum(2^(2*j+1)*(Rt^((2*j)-1)),j,1,N-1))-((t0^2)*symsum(2^(2*j+2)*Rt^(2*j),j,0,N-1));
sigma= area/T^2;
end
syms does a hidden assignment to a variable, and when there are hidden assignments to a variable name that happens to be the same as the name of a function, then MATLAB is permitted to treat the name as a function, because MATLAB does static analysis instead of dynamic analysis.
2 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!