Está en la página 1de 1

clear

clc
//metodo-runge-kutta
//se hace el siguiente cambio x=t,y1=x1,y2=x2
k1=3
k2=0.002
k3=0.0006
k4=0.5
deff('yp1=fun1(x,y1,y2)','yp1=k1*y1-k2*y2*y1')
deff('yp2=fun2(x,y1,y2)','yp2=k3*y1*y2-k4*y2')
h=input('ingrese el tamao de paso ')
x(1,1)=input('ingrese el tiempo inicial ')
y(1,1)=input('ingrese el numero de presas iniciales ')
y(1,2)=input('ingrese el numero depredadores iniciales ')
x0=input('ingrese el tiempo a estimar ')
i=1
t=x(1,1)+h
for p=t:h:x0
k(1,1)=fun1(x(i,1),y(i,1),y(i,2))
k(1,2)=fun2(x(i,1),y(i,1),y(i,2))
a(1,1)=x(i,1)+(h/2)
a(2,1)=y(i,1)+(k(1,1)*h)/2
a(2,2)=y(i,2)+(k(1,2)*h)/2
k(2,1)=fun1(a(1,1),a(2,1),a(2,2))
k(2,2)=fun2(a(1,1),a(2,1),a(2,2))
a(3,1)=y(i,1)+(k(2,1)*h)/2
a(3,2)=y(i,2)+(k(2,2)*h)/2
k(3,1)=fun1(a(1,1),a(3,1),a(3,2))
k(3,2)=fun2(a(1,1),a(3,1),a(3,2))
a(4,1)=x(i,1)+h
a(5,1)=y(i,1)+k(3,1)*h
a(5,2)=y(i,2)+k(3,2)*h
k(4,1)=fun1(a(4,1),a(5,1),a(5,2))
k(4,2)=fun2(a(4,1),a(5,1),a(5,2))
y(i+1,1)=y(i,1)+((1/6)*(k(1,1)+2*k(2,1)+2*k(3,1)+k(4,1))*h)
y(i+1,2)=y(i,2)+((1/6)*(k(1,2)+2*k(2,2)+2*k(3,2)+k(4,2))*h)
x(i+1,1)=x(i,1)+h
i=i+1
end
title('grafica de especies vs tiempo')
xgrid
plot(x,y(:,1),'y',x,y(:,2),'b')

También podría gustarte