MATLAB: System of differential equations

differential equations

How can I solve the system: x1'(t)=x1-x1^3+x2, x1(0)=X1_0 x2'(t)=3*x1-x2 , x2(0)=x2_0 ?

Best Answer

Main program
y0=[0 1];
tspan=[0 10];
[t,y]=ode45(@myeq,tspan,y0)
save this function as myeq.m
function dx=myeq(t,x)
dx=zeros(2,1);
dx(1)=x(1)-x(1)^3+x(2);
dx(2)=3*x(1)-x(2) ;