How to calculate sum without loop?
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
KSSV
el 12 de Feb. de 2021
n = 1:100 ;
s = sum(n.*cos(n/100))
2 comentarios
Aditya Kommajosula
el 12 de Feb. de 2021
Editada: Aditya Kommajosula
el 12 de Feb. de 2021
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
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!