当前位置:网站首页>Transpose and inverse of [linear algebra 01] matrix
Transpose and inverse of [linear algebra 01] matrix
2022-07-27 09:22:00 【Moon fish and fourteen elements】
I have always wanted to write a summary in this regard , Let's start with the transpose and inverse of the matrix . The content of this article is compiled from the webpage .
Transpose and inverse of matrix
Give the protagonist of this part of the narrative , matrix A And matrices B
A = [ 1 2 3 4 ] B = [ 1 2 3 4 5 6 ] A= \begin{bmatrix}1 &2 \\ 3&4 \end{bmatrix} \ \ \ \ \ B= \begin{bmatrix}1 &2 & 3\\ 4&5 &6 \end{bmatrix} A=[1324] B=[142536]
Matrix creation
stay Python in With the help of Numpy Of array Object can create a two-dimensional array ( Matrix ).
>>> import numpy as np
>>> A = np.array([[1,2],[3,4]])#python use numpy Medium array Create a matrix print(A)
>>> print(A)
[[1 2]
[3 4]]
>>> B = np.array([[1,2,3],[4,5,6]])
>>> print(B)
[[1 2 3]
[4 5 6]]
stay matlab This creation process is easier , Use commas or spaces to separate columns , Use semicolons to separate lines .
>> A = [1,2;3,4]
A =
1 2
3 4
>> B = [1 2 3;4 5 6]
B =
1 2 3
4 5 6
The transpose of the matrix
The transpose of a matrix is Make symmetry around the main diagonal , In other words, the row subscripts and column subscripts of matrix elements are interchanged .
A T = [ 1 3 2 4 ] B T = [ 1 4 2 5 3 6 ] A^{T}= \begin{bmatrix}1 &3 \\ 2&4 \end{bmatrix} \ \ \ \ \ B^{T}= \begin{bmatrix}1 &4 \\ 2&5 \\ 3&6 \end{bmatrix} AT=[1234] BT=⎣⎡123456⎦⎤
Numpy in Provides transpose Function to realize transpose .
>>> At = np.transpose(A)
>>> print(At)
[[1 3]
[2 4]]
>>> Bt = np.transpose(B)
>>> print(Bt)
[[1 4]
[2 5]
[3 6]]
matlab in Transpose can be achieved by directly using a prime ( Conjugate transpose is implemented by default ).
>> At = A'
At =
1 3
2 4
>> Bt = B'
Bt =
1 4
2 5
3 6
The matrix of the inverse
Unlike the transpose of a matrix, which is valid for all matrices , The first object of the inverse of a matrix is a square matrix . For a square array , These concepts are equivalent :
The full rank of a reversible matrix can be transformed into an identity matrix through a finite elementary row transformation, and the determinant of a nonsingular matrix is not 0
From definition , Inverse matrix means that the result of matrix multiplication with the original matrix will be the identity matrix , namely :
A A − 1 = A − 1 A = E AA^{-1}=A^{-1}A=E AA−1=A−1A=E
The augmented matrix solves the inverse matrix
Manually calculate the inverse of a matrix , We generally have three ways , The method of undetermined coefficient 、 Adjoint matrix method and elementary transformation method . Because reversible matrix “ Through finite elementary row transformation, it can be transformed into an identity matrix ” The nature of , So we often use augmented matrix to solve the inverse of general matrix .
With A For example , Easy to calculate A The determinant of is -2, Not for 0, A matrix is reversible , The following shows how to solve with augmented matrix A The steps of the inverse matrix of .
A = [ 1 2 ∣ 1 0 3 4 ∣ 0 1 ] A= \begin{bmatrix}1 &2 & | & 1 & 0 \\ 3&4 & | & 0 &1 \end{bmatrix} A=[1324∣∣1001]
Easy to see , First subtract the second row from the first row and multiply by 3:
A ⇒ [ 1 2 ∣ 1 0 0 − 2 ∣ − 3 1 ] A\Rightarrow \begin{bmatrix}1 &2 & | & 1 & 0 \\ 0&-2 & | & -3 &1 \end{bmatrix} A⇒[102−2∣∣1−301]
then , Add the first line back to the second line :
A ⇒ [ 1 0 ∣ − 2 1 0 − 2 ∣ − 3 1 ] A\Rightarrow \begin{bmatrix}1 &0 & | & -2 & 1 \\ 0&-2 & | & -3 &1 \end{bmatrix} A⇒[100−2∣∣−2−311]
Last , Multiply the second line by negative half :
A ⇒ [ 1 0 ∣ − 2 1 0 1 ∣ 3 2 − 1 2 ] A\Rightarrow \begin{bmatrix}1 &0 & | & -2 & 1 \\ 0&1 & | & \frac{3}{2} &-\frac{1}{2} \end{bmatrix} A⇒[1001∣∣−2231−21]
So there is A The inverse matrix of is
A − 1 = [ − 2 1 3 2 − 1 2 ] A^{-1}= \begin{bmatrix} -2 & 1 \\ \frac{3}{2} &-\frac{1}{2} \end{bmatrix} A−1=[−2231−21]
Easy to see A A − 1 = E AA^{-1} = E AA−1=E, The inverse matrix is indeed correct .
inv() Function to solve the inverse matrix
Numpy Medium linear algebra Library linalg Provides inv() Function to realize the inverse matrix solution of nonsingular matrix .
>>> Ai = np.linalg.inv(A)
>>> print(Ai)
[[-2. 1. ]
[ 1.5 -0.5]]
matlab Similar functions are also provided in inv().
>> Ai = inv(A)
Ai =
-2.0000 1.0000
1.5000 -0.5000
Pseudo inverse
Obviously, nonsingular matrices are in the minority , So for singular matrices and non square matrices , There is no inverse matrix , But we can introduce pseudo inverse matrix as the generalized form of inverse matrix . The mathematical definition is as follows :
If there is a relation with A The transpose matrix of A’ A matrix of the same type X, And satisfy :AXA=A,XAX=X. here , Symmetric matrix X For matrix A The pseudo inverse of , Also called generalized inverse matrix .
Easy to verify Inverse matrix is a special case of generalized inverse matrix , namely
A A − 1 A = E A = A , A − 1 A A − 1 = E A − 1 = A − 1 , among X = A − 1 AA^{-1}A=EA=A , \ \ \ A^{-1}AA^{-1}=EA^{-1}=A^{-1} , among X = A^{-1} AA−1A=EA=A, A−1AA−1=EA−1=A−1, among X=A−1
Satisfy A L A = E A^{L}A = E ALA=E, But not satisfied A A L = E AA^{L}=E AAL=E Matrix A L A^{L} AL It's called a matrix A The left inverse matrix of . Allied , Satisfy A A R = E A A^{R}= E AAR=E, But not satisfied A R A = E A^{R}A=E ARA=E Matrix A R A^{R} AR It's called a matrix A Right inverse matrix of . We discuss it in three ways ( It can be seen that the matrix with smaller rank is always taken ):
- When m≥n when , Full rank , matrix A m × n A_{m\times n} Am×n There is a left inverse matrix , A n × m L = ( A T A ) − 1 A T A^{L}_{n\times m}=(A^{T} A)^{-1}A^{T} An×mL=(ATA)−1AT
- When n≥m when , Row full rank , matrix A m × n A_{m\times n} Am×n There is a right inverse matrix , A n × m R = A T ( A A T ) − 1 A^{R}_{n \times m}= A^{T}(AA^{T})^{-1} An×mR=AT(AAT)−1
- When n =m when , A m × n A_{m \times n} Am×n The rank of is r ≤ m = n r \le m = n r≤m=n, Yes A Singular value decomposition A = U D V T A = UDV^{T} A=UDVT ,A The pseudo inverse matrix of is A + = V D + U T A^{+}=VD^{+}U^{T} A+=VD+UT, among D + D^{+} D+ Is the inverse matrix of singular value matrix , That is, the elements on the protagonist line take the reciprocal .
( It should be pointed out that , Singular value decomposition is a general method , Leave it for discussion when writing singular value decomposition )
We deal with relatively simple B For example , It is known that B Yes :
B = [ 1 2 3 4 5 6 ] B T = [ 1 4 2 5 3 6 ] B= \begin{bmatrix}1 &2 & 3\\ 4&5 &6 \end{bmatrix} \ \ \ \ \ B^{T}= \begin{bmatrix}1 &4 \\ 2&5 \\ 3&6 \end{bmatrix} B=[142536] BT=⎣⎡123456⎦⎤
therefore B B T BB^{T} BBT by
B B T = [ 1 2 3 4 5 6 ] × [ 1 4 2 5 3 6 ] = [ 14 32 32 77 ] BB^{T}= \begin{bmatrix}1 &2 & 3\\ 4&5 &6 \end{bmatrix} × \begin{bmatrix}1 &4 \\ 2&5 \\ 3&6 \end{bmatrix} =\begin{bmatrix}14 &32 \\ 32 & 77 \end{bmatrix} BBT=[142536]×⎣⎡123456⎦⎤=[14323277]
Calculate the determinant of this formula , It is easy to find that its value is -54, Inverse matrix exists . Next, use row transformation to solve the inverse matrix , First the (2,1) Element zeroing :
B B T ⇒ [ 14 32 ∣ 1 0 0 3.857 ∣ − 2.286 1 ] BB^{T} \Rightarrow \begin{bmatrix} 14 &32 & | & 1 & 0 \\ 0 & 3.857 & | & -2.286 & 1 \end{bmatrix} BBT⇒[140323.857∣∣1−2.28601]
then (1,2) Element zeroing :
B B T ⇒ [ 14 0 ∣ 19.967 − 8.297 0 3.857 ∣ − 2.286 1 ] BB^{T} \Rightarrow \begin{bmatrix} 14 &0 & | & 19.967 &-8.297 \\ 0 & 3.857 & | & -2.286 & 1 \end{bmatrix} BBT⇒[14003.857∣∣19.967−2.286−8.2971]
Finally, return the diagonal elements to 1:
B B T ⇒ [ 1 0 ∣ 1.426 − 0.593 0 1 ∣ − 0.593 0.259 ] BB^{T} \Rightarrow \begin{bmatrix} 1 &0 & | & 1.426 &-0.593 \\ 0 & 1 & | & -0.593 & 0.259 \end{bmatrix} BBT⇒[1001∣∣1.426−0.593−0.5930.259]
So there is B The right inverse matrix of is ( There is a certain error ):
B R = B T ( B B T ) − 1 = [ 1 4 2 5 3 6 ] × [ 1.426 − 0.593 − 0.593 0.259 ] = [ − 0.946 − 0.443 − 0.113 0.109 − 0.720 − 0.225 ] B^{R}= B^{T}(BB^{T})^{-1}=\begin{bmatrix}1 &4 \\ 2&5 \\ 3&6 \end{bmatrix} \times \begin{bmatrix} 1.426 &-0.593 \\ -0.593 & 0.259 \end{bmatrix} = \begin{bmatrix} -0.946 &-0.443 \\ -0.113 & 0.109 \\ -0.720 &-0.225 \end{bmatrix} BR=BT(BBT)−1=⎣⎡123456⎦⎤×[1.426−0.593−0.5930.259]=⎣⎡−0.946−0.113−0.720−0.4430.109−0.225⎦⎤
Can verify B R B^{R} BR Is to meet B B R = E B B^{R}= E BBR=E, But not satisfied B R B = E B^{R}B=E BRB=E Matrix , This is what “ Right ” The meaning of .
pinv() Function to solve pseudo inverse matrix
Compared with the complicated discussion of violations , In actual programming, seeking violation is just a line of code . Note that although the inverse matrix is a special case of the inverse matrix , but inv() Ratio pinv() Higher solving efficiency , We solve it separately A and B The generalized inverse matrix of .
Numpy Medium linear algebra Library linalg Provides pinv() Function to solve the violation matrix .
>>> Bpi = np.linalg.pinv(B)
>>> print(Bpi)
[[-0.94444444 0.44444444]
[-0.11111111 0.11111111]
[ 0.72222222 -0.22222222]]
Matlab Similar functions are also provided in pinv().
>> Bpi = pinv(B)
Bpi =
-0.9444 0.4444
-0.1111 0.1111
0.7222 -0.2222
边栏推荐
- 二叉树遍历
- [C language - zero foundation lesson 10] adventure of array Kingdom
- 【云原生之kubernetes实战】在kubernetes集群下部署Rainbond平台
- C language exercises
- Day 7 of learning C language
- The execution sequence of async/await, macro tasks and micro tasks
- 500报错
- [wechat applet] lunar calendar and Gregorian calendar are mutually converted
- QDoubleValidator不生效问题解决办法
- Read the paper snunet CD: a densely connected Siamese network for change detection of VHR images
猜你喜欢

NCCL 集合通信--Collective Operations

Restful

Longest string without duplicate characters

Restful

5g failed to stimulate the development of the industry, which disappointed not only operators, but also mobile phone enterprises

Read the paper learning to measure changes: full revolutionary Siamese metric networks for scene change detect

BGP联邦实验

Some practical, commonly used and increasingly efficient kubernetes aliases
![[wechat applet] lunar calendar and Gregorian calendar are mutually converted](/img/6e/ad01756f8da54901a64c5323e4b747.png)
[wechat applet] lunar calendar and Gregorian calendar are mutually converted

npm install报错 强制安装
随机推荐
ES6 new - Operator extension
【微信小程序】农历公历互相转换
QT uses SQLite to open multiple database files at the same time
BGP联邦实验
Wechat applet 5 - foundation strengthening (not finished)
Day 6 of learning C language
坚果天气
Data interaction based on restful pages
2068. Check whether the two strings are almost equal
【无标题】
拍卖行做VC,第一次出手就投了个Web3
[daily algorithm 94] classic interview question: motion range of robot
全排列递归思路整理
1640. 能否连接形成数组-c语言实现
linux下安装oracle,本地PL/SQL连接Linux下的oracle导入表并新建用户和密码
js call和apply
[C language - zero foundation lesson 14] variable scope and storage class
[leetcode -- the first day of introduction to programming ability] basic data type [statistics of odd numbers within the range / average wage after removing the minimum wage and maximum wage)
Ztree custom title attribute
IDL 6S lookup table