How to solve a system of five linear differential equations
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Ruben
el 20 de Abr. de 2017
Comentada: John D'Errico
el 25 de Abr. de 2017
I want to solve a set of differential equations in Matlab It's a kinetic model of a reaction network. I've been searching for similar questions and I found the following script which I tried to make suitable for my case:
k1 = 0.04;
k2 = 0.02;
k3 = 0.01;
k4 = 0.005;
k5 = 0.004;
k6 = 0;
tspan = [0 15000];
function dy = odefun(t,y)
dy = zeros(5,1);
dy(1) = -(k1+k2)*y(1);
dy(2) = -(k3+k4)*y(2);
dy(3) = k1*y(1)+k3*y(2)-k5*y(3);
dy(4) = k2*y(1)+k4*y(2)-k6*y(4);
dy(5) = k5*y(3)+k6*y(4);
[t,y] = ode45(@odefun,tspan,[40 40 0 0 0]);
plot(t,y(:,1));
end
However at the moment it does not work while it does not give errors when I run the script. Could someone help me to solve this problem?
1 comentario
John D'Errico
el 25 de Abr. de 2017
I would STRONGLY suggest that you read the examples shown in the docs for ODE45. Try them out. Think about why it might be a bad idea to have a function odefun that calls ode45, which then calls odefun, which then calls ode45, ad infinitum.
Respuesta aceptada
Sudarshan Kolar
el 25 de Abr. de 2017
Hello Ruben,
Please use Matlab debugger and step through the code to see the issue. You can also observe values as you debug through the code.
https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html
https://www.mathworks.com/help/matlab/matlab_prog/examine-values.html
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!