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).
Error in (line 31)
x=(x+x(i)).^2;

답변 (2개)

madhan ravi
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.

댓글 수: 1

Sarah Baki-Hashemi
Sarah Baki-Hashemi 2018년 11월 21일
I'm not familiar with those functions. I have just been trying to use many simplier functions to obtain the answer.

댓글을 달려면 로그인하십시오.

Walter Roberson
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
Torsten 2018년 11월 21일
I think you mean "i" instead of "ii".
Walter Roberson
Walter Roberson 2018년 11월 21일
Dang new editor doubles single characters in mobile access .

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2018년 11월 21일

댓글:

2018년 11월 21일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by