How to solve a system of five linear differential equations
조회 수: 2 (최근 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!