Solving a System of ODEs
Mostrar comentarios más antiguos
hello all, I need to solve a system of ODEs but i have no idea how to do it. Any help will be appreciated. The system is: dY1/dt= 6*Y(1)^2+(7*Y(1)*Y(2))-(.067*Y(1)) dY2/dt=3*Y(2)^2-(7*Y(1)*Y(2))-(.04*Y(2)) Y1(t=0)=500 Y2(t=0)=20 time= 0 to 59 years I would really truly appreciate it
Respuestas (1)
Star Strider
el 12 de Nov. de 2017
You did most of it already. You simply need to combine the ODEs into a function to provide to one of the ODE solvers.
The Code —
ode = @(T,Y) [6.*Y(1).^2+(7.*Y(1).*Y(2))-(.067*Y(1)); 3*Y(2).^2-(7*Y(1).*Y(2))-(.04*Y(2))];
tspan = linspace(0, 59, 59);
Y0 = [500; 20];
[T,Y] = ode45(ode, tspan, Y0);
figure(1)
plot(T, Y)
grid
The problem is that I get this warning:
Warning: Failure at t=3.257974e-04. Unable to meet integration tolerances without
reducing the step size below the smallest value allowed (8.673617e-19) at time t.
and it fails to integrate.
Since I have no idea what you are doing, I leave that for you to sort.
2 comentarios
Abdulrahim Ayoub
el 12 de Nov. de 2017
Star Strider
el 12 de Nov. de 2017
With this code:
K1 = 1/25;
K2 = 1/15;
K3 = 7;
K4 = 6;
K5 = 3;
ode = @(T,Y) [K5*Y(1).^2 - (K3*Y(1).*Y(2)) - (K1*Y(1)); K4*Y(2).^2 - (K2*Y(2)) + (K3*Y(1).*Y(2))];
tspan = linspace(0, 59, 59);
Y0 = [500; 20];
[T,Y] = ode15s(ode, tspan, Y0);
figure(1)
plot(T, Y)
grid
I get a similar Warning:
Warning: Failure at t=6.972768e-04. Unable to meet integration tolerances without
reducing the step size below the smallest value allowed (1.734723e-18) at time t.
Obviously something is wrong somewhere. Your initial code appears to be correct. Please check to be certain it is, and that you are using the correct kinetic constants.
Since I believe in plotting to understand what your function is doing, this plot of the derivatives (the ‘ode’ function) is informative:
dYdt(:,1) = Y0;
for k1 = 2:length(tspan);
dYdt(:,k1) = ode(tspan(k1), dYdt(:,k1-1));
end
figure(2)
plot(tspan, dYdt)
grid
The derivatives quickly becomes larger than the largest floating-point numbers can represent.
Categorías
Más información sobre Ordinary Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
