Borrar filtros
Borrar filtros

the Runge-Kutta integration scheme

1 visualización (últimos 30 días)
Lam Chun Ting
Lam Chun Ting el 16 de Nov. de 2012
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 comentarios
Jan
Jan el 20 de Nov. de 2012
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 el 21 de Nov. de 2012
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!!

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 18 de Nov. de 2012
You can compare the results of your function with the one calculated by Matlab's ODE45. Which differences do you see?

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by