简体   繁体   English

如何在MATLAB中求解微分方程组?

[英]How to solve system of differential equations in MATLAB?

When I try to use dsolve to solve symbolically, it cannot find an explicit solution: 当我尝试使用dsolve进行符号求解时,找不到明确的解决方案:

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 然后,我尝试使用以下方法求解并绘制图形,但以下方法无法通过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来解决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. 然后我尝试y0 = [0 0 0 0 0]它可以解决,但不是终端条件。 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. dsolve很擅长求解线性微分方程。 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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