How to solve a system of differential equations without symbolic math lab
11 views (last 30 days)
Show older comments
I have three equations that are similar to these,
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247326/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247327/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247328/image.png)
a, b, c, d, and e are all known and I have initial conditions for X, Y, and Z. I have equations saved in their own functions like this:
function dX = fun_dX(a,b,c,d,X,Y)
dX = a*X*(1-b*X)-c*X*Y-d
end
What functions/code should I be using to solve the system without the use of symbolic math lab? Also, how do I get it in a form that I can plot my answers all on one graph (using hold on)? I tried ode45 to solve them individually (for example solving the first equation with a given Y) but I believe the use of ode45 was wrong because the graph of X vs. t did not make sense.
0 Comments
Answers (1)
Walter Roberson
on 8 Nov 2019
a = whatever; b = whatever; c = whatever; d = whatever; e = whatever;
[t, xyz] = ode45(@(t, XYZ) odefun(t, XYZ, a, b, c, d, e), tspan, xyz0);
plot(t, xyz);
function dXYZ = odefun(t, XYZ, a, b, c, d, e)
X = XYZ(1); Y = XYZ(2); Z = XYZ(3);
dXYZ(1) = a*X*(1-b*X) - c*X*Y - d;
dXYZ(2) = a + b*Y - d*X.^2*Y - c*X*Y;
dXYZ(3) = e*Z + b^2*Z - c*Z*X _ d*Y*Z;
end
5 Comments
Walter Roberson
on 8 Nov 2019
function dXYZ = odefun(t, XYZ, a, b, c, d, e)
X = XYZ(1); Y = XYZ(2); Z = XYZ(3);
dXYZ(1,1) = a.*X.*(1-b.*X) - c.*X.*Y - d;
dXYZ(2,1) = a + b.*Y - d.*X.^2.*Y - c.*X.*Y;
dXYZ(3,1) = e.*Z + b.^2.*Z - c.*Z.*X + d.*Y.*Z;
end
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!