当前位置:网站首页>Complexity analysis of matrix inversion operation (complexity analysis of inverse matrix)
Complexity analysis of matrix inversion operation (complexity analysis of inverse matrix)
2022-06-11 08:59:00 【amcomputer】
Complexity analysis of matrix inversion operation
Complexity analysis of inverse matrix
1 background
I wrote an article about matrix complexity analysis before , I didn't expect so many readers . about IT For those concerned , Combine the basic mathematical knowledge from the code level , We can well understand how the complexity of the matrix is calculated and analyzed . One of the readers suggested “ How to analyze the complexity of matrix inversion ”. Let's discuss it together today , I know , There are many ways to find the inverse of a matrix , Here is the most basic way , Other optimization methods , After reading this blog , Self analysis , Because the principle is basically not much different . This blog is just a guide .
2 Analysis of inverse operation
2.1 The basic principle of finding inverse matrix
Many readers here can easily ignore , Just to review .
( A ∣ E ) = ( E ∣ A − 1 ) (A|E) = (E| A^{-1}) (A∣E)=(E∣A−1)
I believe you are familiar with this formula , That is, after the original matrix is aligned with an identity matrix , Make row and column changes , We get the identity matrix , The right part is the inverse matrix .
Prove the following :
A − 1 ( A ∣ E ) = ( A − 1 A ∣ A − 1 E ) A^{-1}(A|E) = (A^{-1}A| A^{-1}E) A−1(A∣E)=(A−1A∣A−1E)
= ( E ∣ A − 1 ) = (E| A^{-1}) =(E∣A−1)
Think about why ?
because :
A − 1 A = E A^{-1}A=E A−1A=E, Take the right A − 1 A^{-1} A−1 after :
A − 1 E = A − 1 A^{-1}E=A^{-1} A−1E=A−1
So the bridge of change is existence A − 1 A^{-1} A−1
3 Inverse matrix complexity analysis - Gauss elimination
3.1 Code level
/* Function description : Primitive matrix a And an identity matrix E Make a large matrix (A,E), Use elementary transformation to transform a become E, You will get (E,A^{-1}) In the form of * */
void inverseMatrix(double arc[d][d], int n, double ans[d][d])// Calculate the inverse of the matrix
{
/* d = n : Represent dimension arc[d][d] : Original matrix ,dxd ans[d][d] : The changed result matrix ,dxd , Initially initialized to the identity matrix */
int i, j, k;// Column
double max, tempA, tempB, P;
int max_num;
double arcCopy[d][d];
memcpy(arcCopy, arc, 288);
for (i = 0; i < n; i++)
{
ans[i][i] = 1;
}
for (i = 0; i < n; i++)// The first i Column
{
max = fabs(arcCopy[i][i]);
max_num = i;
for (j = i + 1; j < n; j++)// Select principal element
{
if (fabs(arcCopy[j][i]) > max)
{
max = fabs(arcCopy[j][i]);
max_num = j;
}
}
for (k = 0; k < n; k++)// Exchange line
{
tempA = arcCopy[i][k];
arcCopy[i][k] = arcCopy[max_num][k];
arcCopy[max_num][k] = tempA;
tempB = ans[i][k];
ans[i][k] = ans[max_num][k];
ans[max_num][k] = tempB;
}
for (k = i + 1; k < n; k++)
{
P = arcCopy[k][i] / arcCopy[i][i];
for (j = 0; j < n; j++)
{
arcCopy[k][j] = arcCopy[k][j] - arcCopy[i][j] * P;
ans[k][j] = ans[k][j] - ans[i][j] * P;
}
}
}
for (i = 0; i < n; i++)// That's ok
{
P = arcCopy[i][i];
for (j = i; j < n; j++)
{
arcCopy[i][j] = arcCopy[i][j] / P;
}
for (j = 0; j < n; j++)
{
ans[i][j] = ans[i][j] / P;
}
}
for (i = n - 1; i > 0; i--)
{
for (j = i - 1; j >= 0; j--)
{
for (k = 0; k < n; k++)
{
ans[j][k] = ans[j][k] - ans[i][k] * arcCopy[j][i];
}
}
}
}
3.2 result
The time complexity of the inverse matrix is :O(n^3)
The biggest cost is here ,
for (i = n - 1; i > 0; i--)
{
for (j = i - 1; j >= 0; j--)
{
for (k = 0; k < n; k++)
{
ans[j][k] = ans[j][k] - ans[i][k] * arcCopy[j][i];
}
}
}
4 Inverse matrix complexity analysis - Adjoint matrix
This is more direct :
A − 1 = A ∗ / d e t ( A ) A^{-1} = A^{*}/det(A) A−1=A∗/det(A)
namely To calculate A The adjoint matrix of , Calculate again A The determinant value of .
The former The complexity of is : N ∗ O ( N ! ) N*O ( N ! ) N∗O(N!)
The complexity of the latter is : N 2 ∗ O ( ( N − 1 ) ! ) N^2 ∗O((N−1)!) N2∗O((N−1)!)
Therefore, the complexity of solving the adjoint matrix is :
N ∗ O ( N ! ) + N 2 ∗ O ( ( N − 1 ) ! ) N*O ( N ! ) + N^2 ∗O((N−1)!) N∗O(N!)+N2∗O((N−1)!)
ps: This blog only considers the basic operation , Do not consider optimization 
边栏推荐
- Are the test methods of CMVSS TSD No. 302 and 49 CFR 571.302 the same
- SQL基本查询
- How to apply for BS 476-7 sample for display? Is it the same as the display
- kubelet Error getting node 问题求助
- K8S应用(四)—— 搭建redis5 集群(可供外部直接访问)
- Iso8191 test is mentioned in as 3744.1. Are the two tests the same?
- 【237. 删除链表中的节点】
- File system check of the root filesystem failed
- SQL basic query
- 86. separate linked list
猜你喜欢

Sword finger offer 40 Minimum number of K

领导让我重写测试代码,我也要照办嘛?

Intelligent control theory question bank

What if the copied code format is confused?

复制的代码格式混乱怎么办?

How to apply for BS 476-7 sample for display? Is it the same as the display

智能控制理论小题库

What software is required to process raw format images?

【C语言-函数栈帧】从反汇编的角度,剖析函数调用全流程

MySQL核心点笔记
随机推荐
Sword finger offer 51 Reverse pair in array
[C language - data storage] how is data stored in memory?
显示器要申请BS 476-7 怎么送样?跟显示屏一样吗
203. remove linked list elements
How to apply for BS 476-7 sample for display? Is it the same as the display
Screening frog log file analyzer Chinese version installation tutorial
剑指 Offer 18. 删除链表的节点
Matlab r2022a installation tutorial
Question d'entrevue 02.02. Renvoie l'avant - dernier noeud K
682. baseball game
445. 两数相加 II
AS 3744.1标准中提及ISO8191测试,两者测试一样吗?
Erreur de démarrage MySQL "BIND on TCP / IP Port: Address already in use"
MATLAB R2022a 安装教程
剑指 Offer 31. 栈的压入、弹出序列
使用express+mysql创建一个基于nodejs的后台服务
86. 分隔链表
SAP ABAP internal table classification, addition, deletion, modification and query
What if the copied code format is confused?
MySQL startup error "bind on tcp/ip port: address already in use"