How to solve a system of differential equations without symbolic math lab

11 次查看(过去 30 天)
I have three equations that are similar to these,
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.

回答(1 个)

Walter Roberson
Walter Roberson 2019-11-8
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 个评论
Anna
Anna 2019-11-8
What do you mean by that? I've tried changing xyz0 but it hasn't gotten rid of the errors.
Walter Roberson
Walter Roberson 2019-11-8
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

请先登录,再进行评论。

类别

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