matlab 函数 expm
引入
首先来看这么一段代码
>> exp([1]) ans = 2.7183 >>
然后来看这么一段代码
>> expm([1]) ans = 2.7183
区别在于函数分别为expm和exp,结果是一样的,再看下面这段代码
>> exp([1,2;3,4]) ans = 2.7183 7.3891 20.0855 54.5982 >> expm([1,2;3,4]) ans = 51.9690 74.7366 112.1048 164.0738
这次结果不一样了,第一个矩阵很显然就是对应元素exp主要看第二个函数
数值解
看下面这个代码
>> expm([1,2,3]) 错误使用 expm (line 25) 需要的 输入 应为 方阵。
需要的输入为方阵,联想一下,方阵的特点是可以自己乘自己
由泰勒展开,
e
x
=
∑
n
=
0
∞
x
n
n
!
e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!}
ex=n=0∑∞n!xn
>> m = [1,2;3,4]; >> s = [1,0;0,1];%eye(2) >> for ii = 1:1:50 s = s + (m^ii)./(factorial(ii)); end >> s s = 51.9690 74.7366 112.1048 164.0738
所以expm就是将exp的泰勒展开中的x换为对应的矩阵,乘法换为矩阵乘法,第一项由1换为与方阵同阶的单位矩阵
上述方法即是求解expm数值解的方法,求有限的前n项之和,得到数值解
解析解
下来讲述如何求解解析解
L
(
t
n
)
=
∫
t
=
0
t
=
∞
t
n
e
−
s
t
d
t
=
∫
t
=
0
t
=
∞
−
1
s
t
n
d
e
−
s
t
=
∫
t
=
0
t
=
∞
e
−
s
t
d
t
n
s
=
n
s
∫
t
=
0
t
=
∞
t
n
−
1
e
−
s
t
d
t
=
n
s
L
(
t
n
−
1
)
L(t^n) \\ = \int_{t=0}^{t=\infty} t^ne^{-st} \mathrm{d}t\\ = \int_{t=0}^{t=\infty} -\frac{1}{s}t^n \mathrm{d}{e^{-st}}\\ = \int_{t=0}^{t=\infty} e^{-st}\mathrm{d}\frac{t^n}{s} \\ = \frac{n}{s} \int_{t=0}^{t=\infty} t^{n-1}e^{-st} \mathrm{d}t\\ = \frac{n}{s} L(t^{n-1})
L(tn)=∫t=0t=∞tne−stdt=∫t=0t=∞−s1tnde−st=∫t=0t=∞e−stdstn=sn∫t=0t=∞tn−1e−stdt=snL(tn−1)
L ( t 0 ) = ∫ t = 0 t = ∞ e − s t d t = 1 s L(t^0) = \int_{t=0}^{t=\infty} e^{-st}\mathrm{d}t = \frac{1}{s} L(t0)=∫t=0t=∞e−stdt=s1
L ( t n ) = n ! s n + 1 L(t^{n}) = \frac{n!}{s^{n+1}} L(tn)=sn+1n!
L ( e x p m ( M t ) ) = I ∑ n = 0 ∞ ( 1 n ! × n ! s n + 1 × M n ) = I ∑ n = 0 ∞ ( M n s n + 1 ) M L ( e x p m ( M t ) ) = I ∑ n = 0 ∞ ( 1 n ! × n ! s n + 1 × M n + 1 ) = I ∑ n = 0 ∞ ( M n + 1 s n + 1 ) ( s I ) L ( e x p m ( M t ) ) = I ∑ n = 0 ∞ ( M n s n ) ( s I − M ) L ( e x p m ( M t ) ) = I L(expm(Mt)) = I\sum_{n=0}^{\infty} (\frac{1}{n!}\times\frac{n!}{s^{n+1}}\times M^n) = I\sum_{n=0}^{\infty} (\frac{M^n}{s^{n+1}})\\ ML(expm(Mt)) = I\sum_{n=0}^{\infty} (\frac{1}{n!}\times\frac{n!}{s^{n+1}}\times M^{n+1}) = I\sum_{n=0}^{\infty} (\frac{M^{n+1}}{s^{n+1}})\\ (sI)L(expm(Mt)) =I\sum_{n=0}^{\infty} (\frac{M^n}{s^{n}})\\ (sI-M)L(expm(Mt)) = I L(expm(Mt))=In=0∑∞(n!1×sn+1n!×Mn)=In=0∑∞(sn+1Mn)ML(expm(Mt))=In=0∑∞(n!1×sn+1n!×Mn+1)=In=0∑∞(sn+1Mn+1)(sI)L(expm(Mt))=In=0∑∞(snMn)(sI−M)L(expm(Mt))=I
L ( e M t ) = ∫ t = 0 t = ∞ e ( M − s I ) t d t = ( s I − M ) − 1 L(e^{Mt}) = \int_{t=0}^{t=\infty} e^{(M-sI)t}\mathrm{d}t = ({sI-M})^{-1} L(eMt)=∫t=0t=∞e(M−sI)tdt=(sI−M)−1
L ( e x p m ( M t ) ) = ( s I − M ) − 1 L(expm(Mt)) = (sI-M)^{-1} L(expm(Mt))=(sI−M)−1
然后就可以求解了
M
=
[
1
2
3
4
]
s
I
−
M
=
[
s
−
1
−
2
−
3
s
−
4
]
二阶方阵用伴随矩阵求逆矩阵
c
o
m
p
a
n
(
s
I
−
M
)
=
[
s
−
4
2
3
s
−
1
]
d
e
t
(
s
I
−
M
)
=
(
s
−
1
)
(
s
−
4
)
−
6
=
s
2
−
5
s
−
2
i
n
v
(
s
I
−
M
)
=
1
s
2
−
5
s
−
2
[
s
−
4
2
3
s
−
1
]
M = \begin{bmatrix} {1}&{2}\\ {3}&{4}\\ \end{bmatrix} \\ sI - M = \begin{bmatrix} {s-1}&{-2}\\ {-3}&{s-4}\\ \end{bmatrix} \\二阶方阵用伴随矩阵求逆矩阵 \\ compan(sI-M) = \begin{bmatrix} {s-4}&{2}\\ {3}&{s-1}\\ \end{bmatrix} \\ det(sI-M) = (s-1)(s-4)-6 = {s^2-5s-2} \\ inv(sI-M) = \frac{1}{s^2-5s-2}\begin{bmatrix} {s-4}&{2}\\ {3}&{s-1}\\ \end{bmatrix}
M=[1324]sI−M=[s−1−3−2s−4]二阶方阵用伴随矩阵求逆矩阵compan(sI−M)=[s−432s−1]det(sI−M)=(s−1)(s−4)−6=s2−5s−2inv(sI−M)=s2−5s−21[s−432s−1]
然后部分分式法解逆拉普拉斯变化,代入t = 1
[
11
−
33
22
e
x
1
+
11
+
33
22
e
x
2
2
33
33
(
e
x
1
−
e
x
2
)
33
11
(
e
x
1
−
e
x
2
)
11
+
33
22
e
x
1
+
11
−
33
22
e
x
2
]
\begin{bmatrix} \frac{11-\sqrt{33}}{22}e^{x_1}+ \frac{11+\sqrt{33}}{22}e^{x_2} & \frac{2\sqrt{33}}{33}(e^{x_1}-e^{x_2}) \\ \frac{\sqrt{33}}{11}(e^{x_1}-e^{x_2})& \frac{11+\sqrt{33}}{22}e^{x_1}+ \frac{11-\sqrt{33}}{22}e^{x_2}\\ \end{bmatrix}
[2211−33ex1+2211+33ex21133(ex1−ex2)33233(ex1−ex2)2211+33ex1+2211−33ex2]
其中 x 1 = 5 + 33 2 x 2 = 5 − 33 2 \begin{matrix} 其中 \\ x1 = \frac{5+\sqrt{33}}{2} \\ x2 = \frac{5-\sqrt{33}}{2} \end{matrix} 其中x1=25+33x2=25−33
>> x1 = (5+sqrt(33))/2; >> x2 = (5-sqrt(33))/2; >> a1 = (11-sqrt(33))/22; >> a2 = (11+sqrt(33))/22; >> b1 = 2*sqrt(33)/33; >> b2 = sqrt(33)/11; >> [a1*exp(x1) + a2*exp(x2) b1*(exp(x1)-exp(x2)) b2*(exp(x1)-exp(x2)) a2*exp(x1) + a1*exp(x2)] ans = 51.9690 74.7366 112.1048 164.0738