How to use symsum function inside a function
조회 수: 24 (최근 30일)
이전 댓글 표시
Chandra Sekhar Kommineni
2022년 1월 9일
댓글: 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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!