sum of series. Vectorised (no loop)
Afficher commentaires plus anciens
How can I sum n terms of
1-1/2+1/3-1/4......
Réponse acceptée
Plus de réponses (2)
Mohammad Ali
le 27 Avr 2021
1 commentaire
DGM
le 27 Avr 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
Catégories
En savoir plus sur Calendar dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!