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

Réponses (1)

Star Strider
Star Strider le 12 Nov 2017

0 votes

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 commentaires

Abdulrahim Ayoub
Abdulrahim Ayoub le 12 Nov 2017
Im trying to model a set of reactions that i can use in my kinetics class. So, y1 and y2 are technically concentrations of species A and B, and the numbers are the rate constants.
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.

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by