Info
この質問は閉じられています。 編集または回答するには再度開いてください。
現在この質問をフォロー中です
- アクティビティ フィードにアップデートが表示されます。
- 通知基本設定に応じて電子メールを受け取ることができます。
invalid index in program
1 ビュー (過去 30 日間)
表示 古いコメント
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 件のコメント
Jan
2022 年 2 月 24 日
Please post the complete error message or explain the difference between the results and your expectations. It is easier to fix a problem than to guess, what the problem is.
Rik
2022 年 2 月 24 日
My first revision would be to remove the //. That is not a valid Matlab syntax. This isn't your first question. You know how this works.
shiv gaur
2022 年 2 月 24 日
this is the well known lorenz equation change in power series solution graph may be like that lorenz
Jan
2022 年 2 月 24 日
@shiv gaur: Again: Please explain as accurate as possible what the problem with your code is. You see, that the "//" is not accepted by Matlab, so simply remove it.
The explanation, that the code should show the Lorenz attractor does not help to understand, what your problem is.
shiv gaur
2022 年 2 月 24 日
編集済み: Jan
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);
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)
revise program
shiv gaur
2022 年 2 月 24 日
this is the lorenz attractor problem that can be solve by power series method i make code by power series method iplace of ode system the result of lorenz by ode is not matching by power series my program of power series lorenz
Jan
2022 年 2 月 24 日
"the result of lorenz by ode is not matching by power series my program of power series lorenz" -
Your code does not run due to the programming error, so how can the results differ?
shiv gaur
2022 年 2 月 24 日
編集済み: Rik
2022 年 2 月 24 日
this is the program of lorenz using time step
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)+(-x(step)*c(step)+r*a(step)-b(step))*dt;
c(step+1)=c(step)+(a(step)*b(step)-p*z(step))*dt;
time(step+1) = time(step) + dt;
end;
Unrecognized function or variable 'x'.
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
2022 年 2 月 24 日
I understand that there may be a language barrier, but I can't imagine that in your native language 'revise program' would be considered a polite request. You're asking strangers to do you a favor. Right now it looks like you're not prepared to put in any effort explaining your question. Lucky for you that Walter and Jan are kinder than I am.
Please read the link that Jan provided. Please use interpunction and line breaks. Remember that it is easy for people to ignore your post. If you make your problem clear, you will increase the chances that someone will enjoy your question as a puzzle. The puzzle should not be understanding your question, but rather how to solve it.
You have accepted 3 answers out of the many your received. You should consider how you can make your questions different so you actually get answers that solve enough of your questions to be accepted.
shiv gaur
2022 年 2 月 24 日
sir if you understand the problem then you can help to solve the minor problem that I have so you are requested to do so
Jan
2022 年 2 月 24 日
@shiv gaur: The code you have posted does not run:
b(step+1)=b(step)+(-x(step)*c(step)+r*a(step)-b(step))*dt;
% ^ x is undefined
There is no chance to guess, what your problem is. You do not mention, what your problem is. Your code does not run and in consequence it does not show, what your problem is.
So how can we help you?
- Post running code.
- Use left button of the toolbar's "Code" section to format the code to improve the readbility.
- Explain in clear word, what the problem is.
shiv gaur
2022 年 2 月 24 日
編集済み: Rik
2022 年 2 月 24 日
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*z(step))*dt;
time(step+1) = time(step) + dt;
end;
Unrecognized function or variable 'z'.
subplot (2,1,1);
plot(time,z,'b' );
xlabel('time');
ylabel('z');
subplot (2,1,2);
plot (x,z,'g' );
xlabel('x');
ylabel('z')
this is edit program lorenz
2.program using power series not matching
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
Jan
2022 年 2 月 24 日
編集済み: Jan
2022 年 2 月 24 日
@shiv gaur: Seriously?! Both code block are still not running:
c(step+1)=c(step)+(a(step)*b(step)-p*z(step))*dt;
% ^ undefined variable z
and:
sumS=sumS+a(i)*c(i-npoints);
% ^^^^^^^^^ causes a negative index
Your question "why not giving match plot" is not meaningful: Both codes do not procude any plot, because they stop with errors.
You do not care about a proper formating - do you see, that I've spend the time for apply the code formatting in your contributions? You repeatedly post not running code. You ignore questions for clarifications still do not mention, what the problem is you want to solve.
This is not a fair usage of this forum.
Please confirm, that you have read and understood this: https://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
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
2022 年 2 月 24 日
c
l
i
c
k
t
h
e
f
o
r
m
a
t
b
u
t
t
o
n
s
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 件のコメント
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.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します: .
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)