How to find sum using single statement?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Airas Akhtar
am 27 Okt. 2014
Bearbeitet: Mischa Kim
am 27 Okt. 2014
I had to find the sum of the series 1/2+(1/2)^2+....(1/2)^100
why does my code not work?
(ones(1,100).*1/2).^([1:100])
it gives the answer zero.
0 Kommentare
Akzeptierte Antwort
Mischa Kim
am 27 Okt. 2014
Bearbeitet: Mischa Kim
am 27 Okt. 2014
Airas, use
f = sum(arrayfun(@(x) 0.5^x,1:100))
or, with your approach, add the sum()
f = sum((ones(1,100).*1/2).^([1:100]))
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dynamic System Models finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!