sum of series. Vectorised (no loop)
Ältere Kommentare anzeigen
How can I sum n terms of
1-1/2+1/3-1/4......
Akzeptierte Antwort
Weitere Antworten (2)
Mohammad Ali
am 27 Apr. 2021
1 Kommentar
DGM
am 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
Kategorien
Mehr zu Calendar finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!