How to solve a system of five linear differential equations

1 次查看(过去 30 天)
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 个评论
John D'Errico
John D'Errico 2017-4-25
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.

请先登录,再进行评论。

采纳的回答

Sudarshan Kolar
Sudarshan Kolar 2017-4-25
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 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by