필터 지우기
필터 지우기

Invalid index showing Index exceeds the number of array elements. Index must not exceed 1.

조회 수: 1 (최근 30일)
a(1)=1;
b(1)=1;
c(1)=1;
S=0;
Z=0;
for i=1:20
for p=1:i-1
a(i+1)=(1/(i+1))*(a(i)-b(i));
S=S+a(p)*c(i-p);
b(i+1)=(1/(i+1))*(a(i)-S-b(i));
Z=Z+a(p)*b(i-p);
c(i+1)=(1/(i+1))*(Z-c(i));
disp([S Z])
end
end
Index exceeds the number of array elements. Index must not exceed 1.
display is showing

채택된 답변

Torsten
Torsten 2022년 3월 6일
For i=1, the p-loop is empty since your loop index goes from p=1:i-1.
Thus for i=1, a(i+1) = a(2), b(i+1) = b(2) and c(i+1) = c(2) will not be defined.
But for i=2, you refer to a(2), b(2) and c(2) in the p-loop in the expressions for a(3), b(3) and c(3). This causes the error.
  댓글 수: 13
shiv gaur
shiv gaur 2022년 3월 6일
a(1)=0;
b(1)=1;
c(1)=0;
z=0;
s=0;
for i=1:20
for p=1:1:i-1
s=s+(a(p)*c(i-p))
z=z+(a(p)*b(i-p))
c(i+1)=(1/(i+1))*((z-c(i)));
b(i+1)=(1/(i+1))*((a(i))-(b(i))-(s));
a(i+1)=(1/(i+1))*(a(i)-b(i));
end
end
pl the program
shiv gaur
shiv gaur 2022년 3월 6일
the p loop for calculating the value of s and z ie
s=s+sum(a(p)*c(i-p));z=s+sum(a(p)*b(i-p))
first how to calculate the z s form this because this is complexity of s z

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by