简体   繁体   中英

How to solve system of differential equations in MATLAB?

When I try to use dsolve to solve symbolically, it cannot find an explicit solution:

T = 5;
r = 0.005;

dsolve(
'Dp11 = p12^2/r - 4*p12 - 2',
'Dp12 = p12 - p11 - 2*p22 + (p12*p22)/r',
'Dp22 = 2*p22 - 2*p12 + p22^2/r',
'Dg1 = g2*(p12/r - 2) - 1',
'Dg2 = g2*(p22/r + 1) - g1',
'p11(T)=1',
'p12(T)=0',
'p22(T)=0',
'g1(T)=0.5',
'g2(T)=0')

syms x1 x2
x = [x1; x2];
u = -inv(R)*B'*(P*x - g)

u = -(p12*x1 - g2 + p22*x2)/r

dsolve(
'Dp11 = p12^2/r - 4*p12 - 2',
'Dp12 = p12 - p11 - 2*p22 + (p12*p22)/r',
'Dp22 = 2*p22 - 2*p12 + p22^2/r',
'Dg1 = g2*(p12/r - 2) - 1',
'Dg2 = g2*(p22/r + 1) - g1')

T = 5;
r = 0.005;
dsolve('Dp11 = p12^2/0.005 - 4*p12 - 2','Dp12 = p12 - p11 - 2*p22 + (p12*p22)/0.005','Dp22 = 2*p22 - 2*p12 + p22^2/0.005','Dg1 = g2*(p12/0.005 - 2) - 1','Dg2 = g2*(p22/0.005 + 1) - g1')
dsolve('Dp11 = p12^2/0.005 - 4*p12 - 2','Dp12 = p12 - p11 - 2*p22 + (p12*p22)/0.005','Dp22 = 2*p22 - 2*p12 + p22^2/0.005','Dg1 = g2*(p12/0.005 - 2) - 1','Dg2 = g2*(p22/0.005 + 1) - g1','p11(5)=1','p12(5)=0','p22(5)=0','g1(5)=0.5','g2(5)=0')

Then I try the following to solve and plot graph but the following can not be solved by ode45, failure at t = 2.39e-001 Unable to meet integration tolerances without reducing the step size below the smallest value allowed (4.44e-016) at time t

Then I try y0 = [0 0 0 0 0] it can solve however it is not the terminal condition. How should I solve this?

t0 = 0;
tf = 5;
y0 = [1 0 0 0.5 0];
[X, Y] = ode45(@exampleode, [t0 tf], y0);

function dy = exampleode(t, y)
r = 0.005;
dy = zeros(5, 1);
dy(1) = y(2)^2/r - 4*y(2) - 2;
dy(2) = y(2) - y(1) - 2*y(3) + (y(2)*y(3))/r;
dy(3) = 2*y(3) - 2*y(2) + y(3)^2/r;
dy(4) = y(5)*(y(2)/r - 2) - 1;
dy(5) = y(5)*(y(3)/r + 1) - y(4);

dsolve is decent at solving linear differential equations. Your problem is that you're throwing a non-linear differential at it which appears to be more then it can handle. Look at this way: there is no general solution for a fifth degree polynomial equation: each solution must be found numerically.

Re your second problem, not sure if you picked up on this, but your equation is extremely unstable!

[X, Y] = ode45(@exampleode, [t0 0.238], y0);
plot (X,Y)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM