- #1
latitude
- 56
- 0
Hi, I've just started using Octave and I'd like to use it to solve and plot a system of differential equations, but I keep getting the same error which I don't understand. What have I done wrong in my code?
Outline:
Initial conditions
x1 = 1
x2 = 1.27 x 10^-6
x3 = 0
t = 0 - 140 days
Equations
dx1 = -0.5*x(1)*x(2)
dx2 = 0.5*x(1)*x(2) - 0.25*x(3)
dx3 = 0.25*x(2)
Code:
%function
function xdot = m (x, t)
xdot = zeros (3,1);
xdot(1) = -0.5*x(1)*x(2);
xdot(2) = 0.5*x(1)*x(2) - 0.25*x(3);
xdot(3) = 0.25*x(2);
endfunction
%initial conditions
x0 = [1;1.27e-06;0];
t = linspace (0,140);
%solve
y = lsode ("m",x0,t)
%plot
plot (y,t)
the error I get says
lsode: repeated convergence failures
Thanks!
Outline:
Initial conditions
x1 = 1
x2 = 1.27 x 10^-6
x3 = 0
t = 0 - 140 days
Equations
dx1 = -0.5*x(1)*x(2)
dx2 = 0.5*x(1)*x(2) - 0.25*x(3)
dx3 = 0.25*x(2)
Code:
%function
function xdot = m (x, t)
xdot = zeros (3,1);
xdot(1) = -0.5*x(1)*x(2);
xdot(2) = 0.5*x(1)*x(2) - 0.25*x(3);
xdot(3) = 0.25*x(2);
endfunction
%initial conditions
x0 = [1;1.27e-06;0];
t = linspace (0,140);
%solve
y = lsode ("m",x0,t)
%plot
plot (y,t)
the error I get says
lsode: repeated convergence failures
Thanks!