Summing without nested loops
Ältere Kommentare anzeigen
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 Kommentare
madhan ravi
am 25 Apr. 2019
Tes?
Stephen23
am 25 Apr. 2019
Tes is the function defined at the start of the code (there are two functions altogether).
madhan ravi
am 25 Apr. 2019
Bearbeitet: madhan ravi
am 25 Apr. 2019
;), yes totally missed it, usually the questions contains the function definition at the end.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!