Runge-Kutta 3

조회 수: 1 (최근 30일)
Abdelkarim Zribi
Abdelkarim Zribi 2019년 3월 27일
편집: John D'Errico 2019년 3월 30일
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
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개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by