ode45 for non linear ODEs
古いコメントを表示

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
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
2021 年 3 月 10 日
Yes, I only wnat to know the solution code for the system.
回答 (1 件)
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 件のコメント
Zainab Alabdulali
2021 年 3 月 10 日
Thank you.
So, what about the plot for product concentration p(t)? can you find the plot for that? assuming the initial conditions s(0)=10, e(0)=3, c(0)=0 and p(0)=0
Jorg Woehl
2021 年 3 月 10 日
編集済み: Jorg Woehl
2021 年 3 月 11 日
Yes - it's the purple line at the bottom of the plot. I have added the output variables and a legend to the answer, which makes it easier to see how to get to all of the concentrations.
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
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...
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!