필터 지우기
필터 지우기

the Runge-Kutta integration scheme

조회 수: 1 (최근 30일)
Lam Chun Ting
Lam Chun Ting 2012년 11월 16일
implement Runge-Kutta integration scheme with the delta=0.005
dx/dt=-x*(2-y), t0=0, x(t0)=1
dy/dt=y*(1-2*x), t0=0, y(t0)=2
but I am not sure the matlab code for Runge-Kutta integration method 4 steps
May anyone help me please?
Many thanks for helping!
  댓글 수: 4
Jan
Jan 2012년 11월 20일
You can find a lot of Runge-Kutta implementations in the net. I suggest to use one of them and convert it to Matlab. If you get problems, post the code you have and ask for a specific line of code.
Lam Chun Ting
Lam Chun Ting 2012년 11월 21일
I try this in another way however, I think the phase curve is not right..Can you tell where did I get wrong please?
The following is my matlab code
function [x_out,y_out,t_out]=Runge_Kutta1(Delta_in,T0,T)
% setting up parameters of the integration
t_max=T;
t_min=T0;
Delta=Delta_in;
t=t_min:Delta:t_max;
x=zeros(1,size(t,2));
y=zeros(1,size(t,2));
z=zeros(1,2);
z(1)=1;
z(2)=2;
for i=1:size(t,2)
x(i)=z(1);
y(i)=z(2);
z1=competing_species_rhs2([z(1),z(2)]);
z2=competing_species_rhs2([z(1)+Delta/2,z(2)+Delta/2*z1]);
z3=competing_species_rhs2([z(1)+Delta/2,z(2)+Delta/2*z2]);
z4=competing_species_rhs2([z(1)+Delta,z(2)+Delta/2]);
z=z+Delta*((z1+2*z2+2*z3+z4)/6);
end;
t_out=t;
x_out=x;
y_out=y;
function z_out=competing_species_rhs2(z)
p=zeros(1,2);
p(1)=-z(1)*(2-z(2));
p(2)=z(2)*(1-2*z(1));
z_out=p;
Many thanks for helping!!

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2012년 11월 18일
You can compare the results of your function with the one calculated by Matlab's ODE45. Which differences do you see?

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by