Summation Problem With Error
显示 更早的评论
Find ∑(xi+i)2 for i=4 to 163
xi represents the 'i'th value in the list of x values.
This is what I have coded...
x=0;
for i=4:163;
x=(x+x(i)).^2;
end
x
But it says this:
Index exceeds the number of array elements (1).
x=(x+x(i)).^2;
回答(2 个)
madhan ravi
2018-11-21
编辑:madhan ravi
2018-11-21
0 个投票
x is only defined as a scalar value which is zero so when you try to acess 2nd element it gives an error. Cumsum/symsum is recommended for your case.
Walter Roberson
2018-11-21
编辑:Walter Roberson
2018-11-21
0 个投票
i = 4:163;
sum( (i+x(i)).^2)
This expects x to already have been defined
2 个评论
Torsten
2018-11-21
I think you mean "i" instead of "ii".
Walter Roberson
2018-11-21
Dang new editor doubles single characters in mobile access .
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!