这篇文章摘抄自沙昌基教授《数理战术学》第七章 多兵种对多兵种作战的微分对策模型,提供了求解微分方程的代码,防止自己忘记。
【例】最优火力分配矩阵随时间变化的例子
设一对二作战中双方的实力向量为
x
=
[
x
1
]
,
y
=
[
y
1
y
2
]
x=[x_1],\quad y=\begin{bmatrix} y_1 \\ y_2 \end{bmatrix}
x=[x1],y=[y1y2]
其初值为
x
10
=
100
,
y
10
=
30
,
y
20
=
30
x_{10}=100,\quad y_{10}=30,\quad y_{20}=30
x10=100,y10=30,y20=30
双方毁伤系数矩阵为
A
=
[
1
1
]
,
B
=
[
9
1
]
A=\begin{bmatrix} 1\\ 1 \end{bmatrix},\quad B = \begin{bmatrix} 9 & 1 \end{bmatrix}
A=[11],B=[91]
火力分配矩阵为
Φ
=
[
ϕ
1
ϕ
2
]
,
Ψ
=
[
ψ
1
ψ
2
]
\Phi=\begin{bmatrix} \phi_1 \\ \phi_2 \end{bmatrix},\quad \Psi=\begin{bmatrix} \psi_1 & \psi_2 \end{bmatrix}
Φ=[ϕ1ϕ2],Ψ=[ψ1ψ2]
其中
0
≤
ψ
1
≤
1
,
0
≤
ψ
2
≤
1
,
0
≤
ϕ
1
,
0
≤
ϕ
2
,
ϕ
1
+
ϕ
2
≤
1
0 \le \psi_1 \le 1,\quad 0 \le \psi_2 \le 1, \\ 0 \le \phi_1, \quad 0 \le \phi_2, \quad \phi_1+\phi_2 \le 1
0≤ψ1≤1,0≤ψ2≤1,0≤ϕ1,0≤ϕ2,ϕ1+ϕ2≤1
于是,双方交战的Lanchester方程变为
{
x
˙
1
=
−
9
ψ
1
y
1
−
ψ
2
y
2
,
y
˙
1
=
−
ϕ
1
x
1
,
y
˙
2
=
−
ϕ
2
x
1
.
(1)
\left\{\begin{matrix} \begin{aligned} \dot x_1 &= -9\psi_1 y_1 - \psi_2 y_2, \\ \dot y_1 &= -\phi_1 x_1, \\ \dot y_2 &= -\phi_2 x_1. \end{aligned} \end{matrix}\right. \tag{1}
⎩⎪⎨⎪⎧x˙1y˙1y˙2=−9ψ1y1−ψ2y2,=−ϕ1x1,=−ϕ2x1.(1)
设双方的作战指数向量为
u
=
(
9
)
,
v
=
[
1
9
]
u=(9),\quad v=\begin{bmatrix} 1 \\ 9 \end{bmatrix}
u=(9),v=[19]
战斗时间为
T
=
1
6
l
n
10
+
l
n
10
9
T=\frac{1}{6}\mathrm{ln}10+\mathrm{ln}\frac{10}{9}
T=61ln10+ln910
则支付函数为
Θ
=
Θ
(
x
1
(
T
)
,
y
1
(
T
)
,
y
2
(
T
)
)
=
9
x
1
(
T
)
−
y
1
(
T
)
−
9
y
2
(
T
)
(2)
\Theta=\Theta(x_1(T),y_1(T),y_2(T))=9x_1(T)-y_1(T)-9y_2(T) \tag{2}
Θ=Θ(x1(T),y1(T),y2(T))=9x1(T)−y1(T)−9y2(T)(2)
【解】
(1)构建Hamilton函数,为
H
=
λ
(
−
9
ψ
1
y
1
−
ψ
2
y
2
)
+
μ
1
(
−
ϕ
1
x
1
)
+
μ
2
(
−
ϕ
2
x
1
)
(3)
H=\lambda(-9\psi_1y_1-\psi_2y_2)+\mu_1(-\phi_1x_1)+\mu_2(-\phi_2x_1) \tag{3}
H=λ(−9ψ1y1−ψ2y2)+μ1(−ϕ1x1)+μ2(−ϕ2x1)(3)
(2)根据Hamilton函数,求得协态方程为
{
λ
˙
=
−
∂
H
∂
x
=
μ
1
ϕ
1
+
μ
2
ϕ
2
,
μ
˙
1
=
−
∂
H
∂
y
1
=
9
λ
ψ
1
,
μ
˙
2
=
−
∂
H
∂
y
2
=
λ
ψ
2
(4)
\left\{\begin{matrix} \begin{aligned} \dot \lambda &= -\frac{\partial H}{\partial x}=\mu_1\phi_1+\mu_2\phi_2, \\ \dot \mu_1 &= -\frac{\partial H}{\partial y_1}=9\lambda\psi_1, \\ \dot \mu_2 &= -\frac{\partial H}{\partial y_2}=\lambda\psi_2 \end{aligned} \end{matrix}\right. \tag{4}
⎩⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎧λ˙μ˙1μ˙2=−∂x∂H=μ1ϕ1+μ2ϕ2,=−∂y1∂H=9λψ1,=−∂y2∂H=λψ2(4)
(3)横截条件为
{
λ
(
T
)
=
∂
Θ
∂
x
1
∣
T
=
9
,
μ
1
(
T
)
=
∂
Θ
∂
y
1
∣
T
=
−
1
,
μ
2
(
T
)
=
∂
Θ
∂
y
2
∣
T
=
−
9
(5)
\left\{\begin{matrix} \begin{aligned} \lambda(T) &= \frac{\partial \mathit \Theta}{\partial x_1} \bigg |_T = 9, \\ \mu_1(T) &= \frac{\partial \mathit \Theta}{\partial y_1} \bigg |_T = -1, \\ \mu_2(T) &= \frac{\partial \mathit \Theta}{\partial y_2} \bigg |_T = -9 \end{aligned} \end{matrix}\right. \tag{5}
⎩⎪⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎪⎧λ(T)μ1(T)μ2(T)=∂x1∂Θ∣∣∣∣T=9,=∂y1∂Θ∣∣∣∣T=−1,=∂y2∂Θ∣∣∣∣T=−9(5)
参考单兵种对多兵种作战的微分对策模型对于协态变量的分析可知,恒有
λ
(
t
)
>
0
,
μ
1
(
t
)
<
0
,
μ
2
(
t
)
<
0
,
0
≤
t
≤
T
.
\lambda(t)>0,\quad \mu_1(t)<0,\quad \mu_2(t)<0,\quad 0 \le t \le T.
λ(t)>0,μ1(t)<0,μ2(t)<0,0≤t≤T.
由鞍点条件可知,对于最优火力分配矩阵有
{
ψ
1
(
t
)
=
ψ
2
(
t
)
=
1
,
0
≤
t
≤
T
,
ϕ
1
(
t
)
+
ϕ
1
(
t
)
=
1
,
0
≤
t
≤
T
(6)
\left\{\begin{matrix} \psi_1(t)=\psi_2(t)=1,\quad 0 \le t \le T, \\ \phi_1(t)+\phi_1(t)=1,\quad 0 \le t \le T \end{matrix}\right. \tag{6}
{ψ1(t)=ψ2(t)=1,0≤t≤T,ϕ1(t)+ϕ1(t)=1,0≤t≤T(6)
且当
−
μ
1
(
t
)
>
−
μ
2
(
t
)
-\mu_1(t)>-\mu_2(t)
−μ1(t)>−μ2(t)时,有
ϕ
1
(
t
)
=
1
,
ϕ
2
(
t
)
=
0.
(7)
\phi_1(t)=1,\quad \phi_2(t)=0. \tag{7}
ϕ1(t)=1,ϕ2(t)=0.(7)
当
μ
1
(
t
)
<
−
μ
2
(
t
)
\mu_1(t)<-\mu_2(t)
μ1(t)<−μ2(t)时,有
ϕ
1
(
t
)
=
0
,
ϕ
2
(
t
)
=
1.
(8)
\phi_1(t)=0,\quad \phi_2(t)=1. \tag{8}
ϕ1(t)=0,ϕ2(t)=1.(8)
今因
−
μ
1
(
T
)
<
−
μ
2
(
T
)
-\mu_1(T)<-\mu_2(T)
−μ1(T)<−μ2(T),故在临近时刻
T
T
T 的一个时间区间内上式均成立,即存在
Δ
∈
[
0
,
T
)
\Delta \in [0,T)
Δ∈[0,T),使得
−
μ
1
(
t
)
<
−
μ
2
(
t
)
,
Δ
<
t
≤
T
(9)
-\mu_1(t) < -\mu_2(t), \quad \Delta < t \le T \tag{9}
−μ1(t)<−μ2(t),Δ<t≤T(9)
现在来考察
Δ
\Delta
Δ的最小值,并将这最小值仍记作
Δ
\Delta
Δ。如果该
Δ
>
0
\Delta>0
Δ>0,则意味着
Δ
\Delta
Δ再不能减小,从而必有
−
μ
1
(
Δ
)
=
−
μ
2
(
Δ
)
(9)
-\mu_1(\Delta)=-\mu_2(\Delta) \tag{9}
−μ1(Δ)=−μ2(Δ)(9)
由式
(
8
)
(8)
(8)有
ϕ
1
(
t
)
=
0
,
ϕ
2
(
t
)
=
1
,
Δ
<
t
≤
T
\phi_1(t)=0, \quad \phi_2(t)=1, \quad \Delta < t \le T
ϕ1(t)=0,ϕ2(t)=1,Δ<t≤T
那么,联立式
(
4
)
(4)
(4)、式
(
6
)
(6)
(6)和式
(
8
)
(8)
(8),则式
(
4
)
(4)
(4)变为
{
λ
˙
=
μ
2
,
μ
˙
1
=
9
λ
,
μ
˙
2
=
λ
,
Δ
<
t
≤
T
\left\{\begin{matrix} \begin{aligned} \dot \lambda &= \mu_2, \\ \dot \mu_1 &= 9\lambda, \\ \dot \mu_2 &= \lambda, \end{aligned} \end{matrix}\right. \quad \Delta < t \le T
⎩⎪⎨⎪⎧λ˙μ˙1μ˙2=μ2,=9λ,=λ,Δ<t≤T
考虑终值条件式
(
5
)
(5)
(5)进行求解。
此处编写MATLAB代码求解上述微分方程,仿真代码为
%% 《数理战术学》第7.3节 式(7.23)、式(7.29)
% 【delta < t <= T】 区间
syms lambda(t) mu1(t) mu2(t) T
eq1 = diff(lambda,t)==mu2;con1 = lambda(T)==9;
eq2 = diff(mu1,t)==9*lambda;con2 = mu1(T)==-1;
eq3 = diff(mu2,t)==lambda;con3 = mu2(T)==-9;
sol1 = dsolve(eq1,eq2,eq3,con1,con2,con3);
求解结果为
书中求解结果为
{
λ
=
9
e
T
−
t
,
μ
1
=
−
81
e
T
−
t
+
80
,
μ
2
=
−
9
e
T
−
t
,
(10)
\left\{\begin{matrix} \begin{aligned} \lambda &= 9e^{T-t}, \\ \mu_1 &= -81e^{T-t} + 80, \\ \mu_2 &= -9e^{T-t}, \end{aligned} \end{matrix}\right. \tag{10}
⎩⎪⎨⎪⎧λμ1μ2=9eT−t,=−81eT−t+80,=−9eT−t,(10)
MATLAB求解结果与书中求解结果相同。
下面来求
Δ
\Delta
Δ,因式
(
10
)
(10)
(10)在
Δ
≤
t
≤
T
\Delta \le t \le T
Δ≤t≤T中成立,且
Δ
\Delta
Δ不能再小,故由式
(
9
)
(9)
(9)可得
−
81
e
T
−
Δ
+
80
=
−
9
e
T
−
Δ
⇒
e
T
−
Δ
=
10
9
⇒
T
−
Δ
=
l
n
10
9
⇒
Δ
=
T
−
l
n
10
9
=
1
6
l
n
10
(11)
\begin{aligned} -81e^{T-\Delta}+80&=-9e^{T-\Delta} \\ \Rightarrow e^{T-\Delta}&=\frac{10}{9} \\ \Rightarrow T-\Delta&=\mathrm{ln}\frac{10}{9} \\ \Rightarrow \Delta&=T-\mathrm{ln}\frac{10}{9} \\ &=\frac{1}{6}\mathrm{ln}10 \end{aligned} \tag{11}
−81eT−Δ+80⇒eT−Δ⇒T−Δ⇒Δ=−9eT−Δ=910=ln910=T−ln910=61ln10(11)
此处求解
Δ
\Delta
Δ的MATLAB代码为
%% 《数理战术学》第7.3节 式(7.30)
syms delta
T = (1/6)*log(10) + log((10/9));
res.lambda = subs(sol1.lambda, t, delta);
res.mu1 = subs(sol1.mu1, t, delta);
res.mu2 = subs(sol1.mu2, t, delta);
res.delta = solve(res.mu1==res.mu2, delta);
res.delta = eval(res.delta);
求解结果为
与书中结果相同。
于是,得到
{
λ
(
Δ
)
=
9
⋅
10
9
=
10
,
μ
1
(
Δ
)
=
−
81
⋅
10
9
+
80
=
−
10
,
μ
2
(
Δ
)
=
−
9
⋅
10
9
=
−
10.
(12)
\left\{\begin{matrix} \begin{aligned} \lambda(\Delta) &= 9 \cdot \frac{10}{9} = 10, \\ \mu_1(\Delta) &= -81 \cdot \frac{10}{9} + 80 = -10, \\ \mu_2(\Delta) &= -9 \cdot \frac{10}{9} = -10. \end{aligned} \end{matrix}\right. \tag{12}
⎩⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎧λ(Δ)μ1(Δ)μ2(Δ)=9⋅910=10,=−81⋅910+80=−10,=−9⋅910=−10.(12)
在
t
=
Δ
t=\Delta
t=Δ处,因
λ
(
Δ
)
=
10
>
0
\lambda(\Delta)=10>0
λ(Δ)=10>0,故
μ
˙
1
(
Δ
)
=
9
λ
(
Δ
)
=
90
>
μ
˙
2
(
Δ
)
=
λ
(
Δ
)
=
10.
\dot \mu_1 (\Delta) = 9\lambda(\Delta)=90>\dot \mu_2(\Delta) = \lambda(\Delta) = 10.
μ˙1(Δ)=9λ(Δ)=90>μ˙2(Δ)=λ(Δ)=10.
于是在
t
=
Δ
t=\Delta
t=Δ的左领域内,有
−
μ
1
(
t
)
>
−
μ
2
(
t
)
(13)
-\mu_1(t) > -\mu_2(t) \tag{13}
−μ1(t)>−μ2(t)(13)
由式
(
13
)
(13)
(13)和式
(
7
)
(7)
(7),有
ϕ
1
(
t
)
=
1
,
ϕ
2
(
t
)
=
0
,
0
≤
t
<
Δ
.
\phi_1(t)=1, \quad \phi_2(t)=0, \quad 0 \le t < \Delta.
ϕ1(t)=1,ϕ2(t)=0,0≤t<Δ.
那么,联立式
(
4
)
(4)
(4)、式
(
6
)
(6)
(6)和式
(
8
)
(8)
(8),则式
(
4
)
(4)
(4)变为
{
λ
˙
=
μ
1
,
μ
˙
1
=
9
λ
,
μ
˙
2
=
λ
,
0
≤
t
≤
Δ
\left\{\begin{matrix} \begin{aligned} \dot \lambda &= \mu_1, \\ \dot \mu_1 &= 9\lambda, \\ \dot \mu_2 &= \lambda, \end{aligned} \end{matrix}\right. \quad 0 \le t \le \Delta
⎩⎪⎨⎪⎧λ˙μ˙1μ˙2=μ1,=9λ,=λ,0≤t≤Δ
考虑终值条件式
(
12
)
(12)
(12)进行求解。
此处编写MATLAB代码求解上述微分方程,仿真代码为
%% 《数理战术学》第7.3节 式(7.33)下面的式子
% 【0 <= t <= delta】 区间
syms delta
eq1 = diff(lambda,t)==mu1;
con1 = lambda(delta)==10;
con2 = mu1(delta)==-10;
con3 = mu2(delta)==-10;
sol2 = dsolve(eq1,eq2,eq3,con1,con2,con3);
求解结果为
书中求解结果为
{
λ
=
10
3
e
3
(
t
−
Δ
)
+
20
3
e
3
(
Δ
−
t
)
,
μ
1
=
10
e
3
(
t
−
Δ
)
−
20
e
3
(
Δ
−
t
)
,
μ
2
=
10
9
e
3
(
t
−
Δ
)
−
20
9
e
3
(
Δ
−
t
)
−
80
9
,
(14)
\left\{\begin{matrix} \begin{aligned} \lambda &= \frac{10}{3}e^{3(t-\Delta)} + \frac{20}{3}e^{3(\Delta-t)}, \\ \mu_1 &= 10e^{3(t-\Delta)} - 20e^{3(\Delta-t)}, \\ \mu_2 &= \frac{10}{9}e^{3(t-\Delta)} - \frac{20}{9}e^{3(\Delta-t)} - \frac{80}{9}, \end{aligned} \end{matrix}\right. \tag{14}
⎩⎪⎪⎪⎪⎨⎪⎪⎪⎪⎧λμ1μ2=310e3(t−Δ)+320e3(Δ−t),=10e3(t−Δ)−20e3(Δ−t),=910e3(t−Δ)−920e3(Δ−t)−980,(14)
MATLAB求解结果与书中求解结果相同。
通过求解该微分对策问题,发现甲方最优火力分配策略确实发生了改变。在 [ 0 , Δ ) [0,\Delta) [0,Δ)时间内应集中力量攻击乙方的第一类作战单位,而在 ( Δ , T ] (\Delta,T] (Δ,T]时间内应集中力量攻击乙方第二类作战单位。
下面来求解相应战斗过程的微分方程组
(
1
)
(1)
(1)的解,并证明甲、乙双方作战单位兵力始终保持如下关系
x
1
(
t
)
≥
0
,
y
1
(
t
)
≥
0
,
y
2
(
t
)
≥
0
x_1(t) \ge 0, \quad y_1(t) \ge 0, \quad y_2(t) \ge 0
x1(t)≥0,y1(t)≥0,y2(t)≥0
下面在MATLAB中编写代码求解微分方程组
(
1
)
(1)
(1),为方便求解,将式
(
1
)
(1)
(1)再次写在下面
{
x
˙
1
=
−
9
ψ
1
y
1
−
ψ
2
y
2
,
y
˙
1
=
−
ϕ
1
x
1
,
y
˙
2
=
−
ϕ
2
x
1
.
(1)
\left\{\begin{matrix} \begin{aligned} \dot x_1 &= -9\psi_1 y_1 - \psi_2 y_2, \\ \dot y_1 &= -\phi_1 x_1, \\ \dot y_2 &= -\phi_2 x_1. \end{aligned} \end{matrix}\right. \tag{1}
⎩⎪⎨⎪⎧x˙1y˙1y˙2=−9ψ1y1−ψ2y2,=−ϕ1x1,=−ϕ2x1.(1)
在
t
∈
[
0
,
Δ
)
t \in [0,\Delta)
t∈[0,Δ)时间内,MATLAB仿真代码为
%% 《数理战术学》第7.3节 求解式(7.19)
% 【0 <= t <= delta】 区间
syms x1(t) y1(t) y2(t)
eq1 = diff(x1)==-9*y1-y2; con1 = x1(0)==100;
eq2 = diff(y1)==-x1; con2 = y1(0)==30;
eq3 = diff(y2)==0; con3 = y2(0)==30;
sol3 = dsolve(eq1,eq2,eq3,con1,con2,con3);
求解结果为
书中求解结果为
{
x
1
=
100
e
−
3
t
,
y
1
=
100
3
e
−
3
t
−
10
3
,
y
2
=
30
,
0
≤
t
<
Δ
(15)
\left\{\begin{matrix} \begin{aligned} x_1 &= 100e^{-3t}, \\ y_1 &= \frac{100}{3}e^{-3t}-\frac{10}{3}, \\ y_2 &= 30, \end{aligned} \end{matrix}\right. \tag{15} \quad 0 \le t < \Delta
⎩⎪⎪⎪⎨⎪⎪⎪⎧x1y1y2=100e−3t,=3100e−3t−310,=30,0≤t<Δ(15)
MATLAB求解结果与书中求解结果相同。
在 t ∈ [ Δ , T ] t \in [\Delta,T] t∈[Δ,T]时间内,MATLAB仿真代码为
%% 《数理战术学》第7.3节 求解式(7.19)
% 【delta <= t <= T】 区间
delta = 0.3838;
eq1 = diff(x1)==-9*y1-y2; con1 = x1(0)==subs(sol3.x1,t,delta);
eq2 = diff(y1)==0; con2 = y1(0)==subs(sol3.y1,t,delta);
eq3 = diff(y2)==-x1; con3 = y2(0)==subs(sol3.y2,t,delta);
sol4 = dsolve(eq1,eq2,eq3,con1,con2,con3);
syms delta
sol4.x1 = subs(sol4.x1,t,t-delta);
sol4.y1 = subs(sol4.y1,t,t-delta);
sol4.y2 = subs(sol4.y2,t,t-delta);
求解结果为
书中求解结果为
{
x
1
=
20
10
e
Δ
−
t
−
10
10
e
t
−
Δ
,
y
1
=
10
3
10
−
10
3
,
y
2
=
20
10
e
Δ
−
t
+
10
10
e
t
−
Δ
−
30
10
+
30.
Δ
≤
t
≤
T
(16)
\left\{\begin{matrix} \begin{aligned} x_1 &= 20 \sqrt{10} e^{\Delta-t}-10 \sqrt{10} e^{t-\Delta}, \\ y_1 &= \frac{10}{3} \sqrt{10} - \frac{10}{3}, \\ y_2 &= 20\sqrt{10} e^{\Delta-t} + 10\sqrt{10} e^{t-\Delta} - 30\sqrt{10} + 30. \end{aligned} \end{matrix}\right. \quad \Delta \le t \le T \tag{16}
⎩⎪⎪⎪⎨⎪⎪⎪⎧x1y1y2=2010eΔ−t−1010et−Δ,=31010−310,=2010eΔ−t+1010et−Δ−3010+30.Δ≤t≤T(16)
MATLAB求解结果与式
(
16
)
(16)
(16)相比,得到的式子更加复杂。经过核算,
200*exp(-5757/5000) = 63.2388
100*exp(-5757/5000) = 31.6194
300*exp(-5757/5000) = 94.8683
100*exp(-5757/5000)/3-10/3 = 7.2065
{ 20 10 = 63.2456 , 10 10 = 31.6228 , 30 10 = 94.8683 , 10 3 10 − 10 3 = 7.2076. \left\{\begin{matrix} \begin{aligned} 20\sqrt{10}&=63.2456, \\ 10\sqrt{10}&=31.6228, \\ 30\sqrt{10}&=94.8683, \\ \frac{10}{3} \sqrt{10} - \frac{10}{3} &= 7.2076. \end{aligned} \end{matrix}\right. ⎩⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎧20101010301031010−310=63.2456,=31.6228,=94.8683,=7.2076.
两者相差不多,可以认为MATLAB的求解结果与书中结果相同。
至此,使用MATLAB求解微分方程的问题已解决。
将所求得的表达式画图,在MATLAB中编写代码实现,代码为
%% 画图
% 战斗时间
T = (1/6)*log(10) + log(10/9);
delta = (1/6)*log(10);
% 表达式
k = 1;
len = length(0:0.01:T);
x1 = zeros(1,len);
y1 = zeros(1,len);
y2 = zeros(1,len);
for t = 0:0.01:T
if t <= delta
x1(k) = 100*exp(-3*t);
y1(k) = (100/3)*exp(-3*t) - (10/3);
y2(k) = 30;
k = k+1;
else
x1(k) = 20*sqrt(10)*exp(delta-t) - 10*sqrt(10)*exp(t-delta);
y1(k) = (10/3)*sqrt(10) - (10/3);
y2(k) = 20*sqrt(10)*exp(delta-t) + 10*sqrt(10)*exp(t-delta) - 30*sqrt(10) + 30;
k = k+1;
end
end
figure('Color',[1,1,1]);box on;
t = 0:0.01:T;
plot(t, x1, 'LineWidth', 1.5);hold on;
plot(t, y1, 'LineWidth', 1.5);
plot(t, y2, 'LineWidth', 1.5);
set(gca,'FontName','Times New Roman',...
'FontSize',13,...
'LineWidth',1.3,...
'XTick',(0:0.05:t(end)),...
'YTick',(0:10:110))
legend('x1','y1','y2');
xlabel('时间单位','FontName','宋体');ylabel('兵力','FontName','宋体');
axis([0 t(end) 0 110]);
结果为
全部源码如下(作者的MATLAB版本为2018b ):
clc;clear;
format long; % 将数据精度设置为长精度
%% 《数理战术学》第7.3节 式(7.23)、式(7.29)
% 【delta <= t <= T】 区间
syms lambda(t) mu1(t) mu2(t) T
eq1 = diff(lambda,t)==mu2;con1 = lambda(T)==9;
eq2 = diff(mu1,t)==9*lambda;con2 = mu1(T)==-1;
eq3 = diff(mu2,t)==lambda;con3 = mu2(T)==-9;
sol1 = dsolve(eq1,eq2,eq3,con1,con2,con3);
% sol1=dsolve(diff(lambda)==mu2, diff(mu1)==9*lambda, diff(mu2)==lambda,...
% lambda(T)==9, mu1(T)==-1, mu2(T)==-9);
%% 《数理战术学》第7.3节 式(7.30)
syms delta
T = (1/6)*log(10) + log((10/9));
res.lambda = subs(sol1.lambda, t, delta);
res.mu1 = subs(sol1.mu1, t, delta);
res.mu2 = subs(sol1.mu2, t, delta);
res.delta = solve(res.mu1==res.mu2, delta);
res.delta = eval(res.delta);
%% 《数理战术学》第7.3节 式(7.33)下面的式子
% 【0 <= t <= delta】 区间
syms delta
eq1 = diff(lambda,t)==mu1;
con1 = lambda(delta)==10;
con2 = mu1(delta)==-10;
con3 = mu2(delta)==-10;
sol2 = dsolve(eq1,eq2,eq3,con1,con2,con3);
%% 《数理战术学》第7.3节 求解式(7.19)
% 【0 <= t <= delta】 区间
syms x1(t) y1(t) y2(t)
eq1 = diff(x1)==-9*y1-y2; con1 = x1(0)==100;
eq2 = diff(y1)==-x1; con2 = y1(0)==30;
eq3 = diff(y2)==0; con3 = y2(0)==30;
sol3 = dsolve(eq1,eq2,eq3,con1,con2,con3);
% 【delta <= t <= T】 区间
delta = 0.3838;
eq1 = diff(x1)==-9*y1-y2; con1 = x1(0)==subs(sol3.x1,t,delta);
eq2 = diff(y1)==0; con2 = y1(0)==subs(sol3.y1,t,delta);
eq3 = diff(y2)==-x1; con3 = y2(0)==subs(sol3.y2,t,delta);
sol4 = dsolve(eq1,eq2,eq3,con1,con2,con3);
syms delta
sol4.x1 = subs(sol4.x1,t,t-delta);
sol4.y1 = subs(sol4.y1,t,t-delta);
sol4.y2 = subs(sol4.y2,t,t-delta);
%% 画图
% 战斗时间
T = (1/6)*log(10) + log(10/9);
delta = (1/6)*log(10);
% 表达式
k = 1;
len = length(0:0.01:T);
x1 = zeros(1,len);
y1 = zeros(1,len);
y2 = zeros(1,len);
for t = 0:0.01:T
if t <= delta
x1(k) = 100*exp(-3*t);
y1(k) = (100/3)*exp(-3*t) - (10/3);
y2(k) = 30;
k = k+1;
else
x1(k) = 20*sqrt(10)*exp(delta-t) - 10*sqrt(10)*exp(t-delta);
y1(k) = (10/3)*sqrt(10) - (10/3);
y2(k) = 20*sqrt(10)*exp(delta-t) + 10*sqrt(10)*exp(t-delta) - 30*sqrt(10) + 30;
k = k+1;
end
end
figure('Color',[1,1,1]);box on;
t = 0:0.01:T;
plot(t, x1, 'LineWidth', 1.5);hold on;
plot(t, y1, 'LineWidth', 1.5);
plot(t, y2, 'LineWidth', 1.5);
set(gca,'FontName','Times New Roman',...
'FontSize',13,...
'LineWidth',1.3,...
'XTick',(0:0.05:t(end)),...
'YTick',(0:10:110))
legend('x1','y1','y2');
xlabel('时间单位','FontName','宋体');ylabel('兵力','FontName','宋体');
axis([0 t(end) 0 110]);