How to calculate sum without loop?
17 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I must calculate S in the range of n=1 to n=100 without a loop.
s=(1...100)(101-n)*cos(n/100)
Example= 100*cos(1/100) + 99*cos(2/100) ... + 1*cos(100/100)
0 件のコメント
回答 (1 件)
KSSV
2021 年 2 月 12 日
n = 1:100 ;
s = sum(n.*cos(n/100))
2 件のコメント
Aditya Kommajosula
2021 年 2 月 12 日
編集済み: Aditya Kommajosula
2021 年 2 月 12 日
If I understand the OP's question right, the solution might have to be:
n = 1:100;
s = sum(n(end:-1:1).*cos(n/100));
Regards
参考
カテゴリ
Help Center および 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!