Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

invalid index in program

조회 수: 4 (최근 30일)
shiv gaur
shiv gaur 2022년 2월 24일
마감: Rik 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
shiv gaur
shiv gaur 2022년 2월 24일
sorry jan this is edit program that is running program this is the program of lorenz using time step
we have to plan match with below program using power series now program is right
p=8/3;
r=25;
sigma=10;
npoints =500000;
dt = 0.0001;
a = zeros(npoints,1);
b = zeros(npoints,1);
c = zeros(npoints,1);
time = zeros(npoints,1);
a(1)=1;
b(1)=1;
c(1)=1;
for step = 1:npoints-1
a(step+1)=a(step)+sigma*(b(step)-a(step))*dt;
b(step+1)=b(step)+(-a(step)*c(step)+r*a(step)-b(step))*dt;
c(step+1)=c(step)+(a(step)*b(step)-p*c(step))*dt;
time(step+1) = time(step) + dt;
end;
subplot (2,1,1);
plot(time,z,'b' );
xlabel('time');
ylabel('z');
subplot (2,1,2);
plot (x,z,'g' );
xlabel('x');
ylabel('z')
2.power series
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);
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,sumb)
why not giving match plot
Rik
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
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.

Jan
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