How to find sum using single statement?
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Mischa Kim
2014 年 10 月 27 日
編集済み: Mischa Kim
2014 年 10 月 27 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Dynamic System Models についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!