Here is an example of a single first-order differential equation:
function xdot = f(x,t)
xdot(1)=-x(1);
endfunction;
x0=[1];
t=linspace(0,6,50)’;
x=lsode(“f”,x0,t);
plot(t,x)
Here is a system of differential equations;
both dependent variables are shown in the picture;
function xdot = f(x,t)
xdot(1)=-.5*x(2);
xdot(2)=x(1);
endfunction;
x0=[0;2];
t=linspace(0,10,50)’;
x=lsode(“f”,x0,t);
plot(t,x)
The first example is solving with , on .
The second example is solving
and with and , on .
function xdot = f(x,t)
xdot(1)=(1-2*t)*x(1)^2;
endfunction;
x0=[-1/6];
t=linspace(-1.5,2.5,50)’;
x=lsode(“f”,x0,t);
plot(t,x)