Summing without nested loops
古いコメントを表示
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 件のコメント
madhan ravi
2019 年 4 月 25 日
Tes?
Stephen23
2019 年 4 月 25 日
Tes is the function defined at the start of the code (there are two functions altogether).
madhan ravi
2019 年 4 月 25 日
編集済み: madhan ravi
2019 年 4 月 25 日
;), yes totally missed it, usually the questions contains the function definition at the end.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!