Filter löschen
Filter löschen

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

11 Ansichten (letzte 30 Tage)
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.

Antworten (1)

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

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by