sum of series. Vectorised (no loop)
Mostra commenti meno recenti
How can I sum n terms of
1-1/2+1/3-1/4......
Risposta accettata
Più risposte (2)
Mohammad Ali
il 27 Apr 2021
1 Commento
DGM
il 27 Apr 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
Categorie
Scopri di più su Calendar in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!