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
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
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!