Info

この質問は閉じられています。 編集または回答するには再度開いてください。

# invalid index in program

1 ビュー (過去 30 日間)
shiv gaur 2022 年 2 月 24 日

p=8/3;
r=25;
sigma=10;
npoints =5000;
dt = 0.1;
a = zeros(npoints,1);
b = zeros(npoints,1);
c= zeros(npoints,1);
t = zeros(npoints,1);
//t=1:dt:100;
Invalid use of operator.
a(1)=1;
b(1)=1;
c(1)=1;
suma=0;
sumb=0;
sumc=0;
sumS=0;
sumZ=0;
for i = 1:npoints-1
sumS=sumS+a(i)*c(i-npoints);
sumZ=sumZ+a(i)*b(i-npoints);
a(i+1)=((sigma)/(i+1))*(b(i)-a(i));
b(i+1)=(1/(i+1))*(r*a(i)-b(i)-sumS);
c(i+1)=(1/(i+1))*(sumZ-p*c(i));
suma=suma+a(i).*(t^i);
sumb=sumb+b(i).*(t^i);
sumc=sumc+c(i).*(t^i);
t(i+1) = t(i) + dt;
end;
plot(t,suma)
pl revise the program
##### 20 件のコメント表示 19 件の古いコメント非表示 19 件の古いコメント
Rik 2022 年 2 月 24 日
c
l
i
c
k
t
h
e
f
o
r
m
a
t
b
u
t
t
o
n
s
Click the link Jan gave you. Also click this.
Feel free to reopen the question and edit your last comment.

### 回答 (2 件)

Walter Roberson 2022 年 2 月 24 日
npoints =5000;
for i = 1:npoints-1
sumS=sumS+a(i)*c(i-npoints);
First iteration: i is 1, and a(1) is being indexed; as you initialized a(1) that is valid so far.
Then c(i-npoints) is being indexed. That is c(1-5000) which is c(-4999) which is not a valid index.
##### 0 件のコメント表示 -1 件の古いコメント非表示 -1 件の古いコメント

Jan 2022 年 2 月 24 日
Use the debugger to examine the cause of problems. Type this in the command window:
dbstop if error
Run the code again until it stops at the error.
A guess: c(i-npoints) cannot work, because the index is negative.

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by