ode45 for non linear ODEs
55 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Jorg Woehl
am 10 Mär. 2021
Bearbeitet: Jorg Woehl
am 11 Mär. 2021
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?
Antworten (1)
Jorg Woehl
am 10 Mär. 2021
Bearbeitet: Jorg Woehl
am 11 Mär. 2021
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 Kommentare
Star Strider
am 11 Mär. 2021
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
am 11 Mär. 2021
Bearbeitet: Jorg Woehl
am 11 Mär. 2021
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...
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!