Summation Problem With Error
Show older comments
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;
Answers (2)
madhan ravi
on 21 Nov 2018
Edited: madhan ravi
on 21 Nov 2018
0 votes
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.
1 Comment
Sarah Baki-Hashemi
on 21 Nov 2018
Walter Roberson
on 21 Nov 2018
Edited: Walter Roberson
on 21 Nov 2018
0 votes
i = 4:163;
sum( (i+x(i)).^2)
This expects x to already have been defined
2 Comments
Torsten
on 21 Nov 2018
I think you mean "i" instead of "ii".
Walter Roberson
on 21 Nov 2018
Dang new editor doubles single characters in mobile access .
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!