필터 지우기
필터 지우기

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

조회 수: 11 (최근 30일)
Anna
Anna 2019년 11월 8일
댓글: Walter Roberson 2019년 11월 8일
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