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!