sum of series. Vectorised (no loop)
Mostrar comentarios más antiguos
How can I sum n terms of
1-1/2+1/3-1/4......
Respuesta aceptada
Más respuestas (2)
Mohammad Ali
el 27 de Abr. de 2021
1 comentario
DGM
el 27 de Abr. de 2021
This only gives the correct answer for odd inputs.
You can calculate the sum of a finite alternating harmonic series easy enough:
N = 1000;
n = 1:N;
s = sum((2*mod(n,2)-1)./n)
gives
s =
0.6926
Categorías
Más información sobre Calendar en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!