// Exo 1

function y=f(t,x)
    y=[3*x(1)-x(1)*x(2);x(1)*x(2)-2*x(2)]
endfunction

scf(0)
clf()
fchamp(f,0,[0:0.5:4],[0:0.5:6])


function yy=eulE(y0,dt,tf)
    Y=y0
    yy=[Y]
    for i=1:tf/dt
        Y=Y+dt*f((i-1)*dt,Y)
        yy=[yy,Y]
    end
endfunction

Sol=eulE([1;2],0.05,20)

scf(1)
clf()
plot2d([0:0.05:20]',Sol')


function yy=RK2(y0,dt,tf)
    Y=y0
    yy=[Y]
    for i=1:tf/dt
        Y=Y+dt*f((i-1/2)*dt,Y+(dt/2)*f((i-1)*dt,Y))
        yy=[yy,Y]
    end
endfunction

Sol2=RK2([1;2],0.05,20)

scf(2)
clf()
plot2d([0:0.05:20]',Sol2')

// Exo 2

function y=f2(t,x)
    y=[3*x(1)-x(1)*x(2)-0.01*x(1)^2;x(1)*x(2)-2*x(2)-0.01*x(2)^2]
endfunction

function yy=RK22(y0,dt,tf)
    Y=y0
    yy=[Y]
    for i=1:tf/dt
        Y=Y+dt*f2((i-1/2)*dt,Y+(dt/2)*f2((i-1)*dt,Y))
        yy=[yy,Y]
    end
endfunction

Sol3=RK22([1;2],0.05,20)

scf(3)
clf()
plot2d([0:0.05:20]',Sol3')
