![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/545752/image.png)
ode45 for non linear ODEs
조회 수: 20 (최근 30일)
이전 댓글 표시
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/545732/image.png)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/545752/image.png)
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?
답변 (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
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/545767/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/545772/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/545777/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/545782/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/545797/image.png)
댓글 수: 4
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...
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!