ode45 for non linear ODEs

58 次查看(过去 30 天)
Zainab Alabdulali
Zainab Alabdulali 2021-3-10
编辑: Jorg Woehl 2021-3-11
How can I solve and plot the 4 system of equations in MATLAB, using ode45 for non linear ODEs, assuming the following initial conditions:
s(0) = 10, e(0) = 3, c(0) = 0 & p(0) = 0 ( initailly no complex & product formation is there at t=0)
  2 个评论
Jorg Woehl
Jorg Woehl 2021-3-10
编辑:Jorg Woehl 2021-3-11
I suppose the reaction mechanism is as follows:
Part of what the assignment asks you to do is independent of MATLAB. So, just to be sure: You are not asking for help concerning the actual assignment (in the pasted image), but only want to know how you can numerically solve the system of four ODEs in MATLAB?
Zainab Alabdulali
Zainab Alabdulali 2021-3-10
Yes, I only wnat to know the solution code for the system.

请先登录,再进行评论。

回答(1 个)

Jorg Woehl
Jorg Woehl 2021-3-10
编辑:Jorg Woehl 2021-3-11
The solution below follows closely the "Solve Nonstiff Equation" example in the ode45 documentation.
We first need to write an external function that encodes the differential equations in a single array variable y; let's choose , , , and .
The code for solving the system of ODEs in the range t = 0...20 would then be as follows (change the rate constants to your liking):
% solve the system of ODEs for t=0->20 under the given initial conditions
[t,y] = ode45(@odefun, [0 20], [10; 3; 0; 0]);
% plot the results
plot(t,y(:,1), t,y(:,2), t,y(:,3), t,y(:,4));
legend('s', 'e', 'c', 'p');
% define the system of ODEs to solve
function dydt = odefun(t,y)
k1 = 0.1;
k_1 = 0.05;
k2 = 0.01;
dydt = zeros(4,1);
dydt(1) = k_1*y(3) - k1*y(1)*y(2);
dydt(2) = (k_1 + k2)*y(3) - k1*y(1)*y(2);
dydt(3) = k1*y(1)*y(2) - (k2 + k_1)*y(3);
dydt(4) = k2*y(3);
end
  4 个评论
Star Strider
Star Strider 2021-3-11
This appears to be a homework problem. On MATLAB Answers, it is not considered to be appropriate to give full solutions to homework problems, only hints. Correcting existing code (when provided) is appropriate.
Jorg Woehl
Jorg Woehl 2021-3-11
编辑:Jorg Woehl 2021-3-11
I couldn't agree more with the idea that full solutions to homework problems should not be given, only pointers in the right direction. That's why I wanted to first make sure that Zainab wasn't asking for help with the actual assignment (see my first comment), but only had an auxiliary question that (s)he was curious about.
Perhaps (and quite possibly) my interpretation was naive; my apologies. I think it would be helpful if questions could be flagged as "homework" by the forum moderators before they are published on this forum...

请先登录,再进行评论。

类别

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