Summing without nested loops
Afficher commentaires plus anciens
I have the following code which has 6 for loops to obtain a sum. I was wondering if the sum can be done without the use for loops, since they are very slow in matlab. (Something like vectorizing)
function ts=Tes(i,j,k,l,m,n,x)
ts=beselj(i-j,x)*besselj(j-k,x)*besselj(k-l,x)*besselj(l-m,x)*besselj(l-n,x);
end
function ds=Ds(x)
dds=0;
for i=1:21
for j=1:21
for k=1:21
for l=1:21
for m=1:21
for n=1:21
dds=dds+Tes(i,j,k,l,m,n,x);
end
end
end
end
end
ds=dds;
end
Thanks in advance!
3 commentaires
madhan ravi
le 25 Avr 2019
Tes?
Stephen23
le 25 Avr 2019
Tes is the function defined at the start of the code (there are two functions altogether).
madhan ravi
le 25 Avr 2019
Modifié(e) : madhan ravi
le 25 Avr 2019
;), yes totally missed it, usually the questions contains the function definition at the end.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!