how to use Runge Kutta 3 to solve an equation (2x''-x'²+4=0) for example.I have the initial values and the step sizes. Thanks

6 件のコメント

Jan
Jan 2019 年 3 月 27 日
What have you tried so far? What exactly is "Runge Kutta 3"? Did you convert the equation of order 2 to a system of equations of order 1 already?
James Tursa
James Tursa 2019 年 3 月 27 日
Are you supposed to write your own RK code or can you use a MATLAB solver such as ode45? (Nobody uses an RK3 method because in the derivation the error terms fall out naturally to produce an RK4 method).
Abdelkarim Zribi
Abdelkarim Zribi 2019 年 3 月 29 日
intmin=0; intmax=1; numnodes=21; inival1=1; inival2=1; f1=@(t,x1,x2) 2*x2; f2=@(t,x1,x2) x1^2+4; h=(intmax-intmin)/(numnodes-1); t=zeros(1,numnodes); x1=zeros(1,numnodes); x2=zeros(1,numnodes); t(1)=intmin; x1(1)=inival1; x2(1)=inival2; for i=2:numnodes t(i)=t(i-1)+h; k11=f1(t(i-1),x1(i-1),x2(i-1)); k12=f1(t(i-1)+h/2,x1(i-1)+(h/2)*k11,x2(i-1)+(h/2)*k11); x1(i)=x1(i-1)+h*k12; x2(i)=x2(i-1)+h*f2(t(i-1),x1(i-1),x2(i-1)); end figure plot(t,x2,'.-')
this is what i wrote not sure if it's correct
James Tursa
James Tursa 2019 年 3 月 29 日
Please format your code so that it is readable.
Abdelkarim Zribi
Abdelkarim Zribi 2019 年 3 月 30 日
編集済み: John D'Errico 2019 年 3 月 30 日
intmin=0;
intmax=1;
numnodes=21;
inival1=1;
inival2=1;
f1=@(t,x1,x2) 2*x2;
f2=@(t,x1,x2) x1^2+4;
h=(intmax-intmin)/(numnodes-1);
t=zeros(1,numnodes);
x1=zeros(1,numnodes);
x2=zeros(1,numnodes);
t(1)=intmin;
x1(1)=inival1;
x2(1)=inival2;
for i=2:numnodes
t(i)=t(i-1)+h;
k11=f1(t(i-1),x1(i-1),x2(i-1));
k12=f1(t(i-1)+h/2,x1(i-1)+(h/2)*k11,x2(i-1)+(h/2)*k11);
x1(i)=x1(i-1)+h*k12;
x2(i)=x2(i-1)+h*f2(t(i-1),x1(i-1),x2(i-1));
end
figure
plot(t,x2,'.-')

サインインしてコメントする。

回答 (0 件)

タグ

質問済み:

2019 年 3 月 27 日

編集済み:

2019 年 3 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by