Can anyone tell me the error with sum function?
2 ビュー (過去 30 日間)
古いコメントを表示
r=0.5;
n=0:10;
x=r.^n
s=sum(x)
What's the error with s?
3 件のコメント
Alex Mcaulley
2019 年 12 月 11 日
What is wrong? It is the summation of a geometric progression and the result seems ok:
%Your code
r=0.5;
n=0:10;
x=r.^n
s=sum(x)
%General formula
s2 = x(1) + r*(x(end)-1)/(r-1)
s =
1.9990
s2 =
1.9990
回答 (1 件)
Steven Lord
2019 年 12 月 11 日
Based on prior experience, I suspect you received the error "Array indices must be positive integers or logical values." If that's the case, clear the variable you've created named sum which is preventing you from calling the built-in sum function.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!