How to use symsum function inside a function
26 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Chandra Sekhar Kommineni
il 9 Gen 2022
Commentato: Chandra Sekhar Kommineni
il 9 Gen 2022
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 Commenti
Risposta accettata
Walter Roberson
il 9 Gen 2022
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Calculus in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!