> 文章列表 > C#,码海拾贝(15)——“对称正定矩阵”的求逆和“托伯利兹矩阵”求逆的“埃兰特”方法之C#源代码,《C#数值计算算法编程》源代码升级改进版

C#,码海拾贝(15)——“对称正定矩阵”的求逆和“托伯利兹矩阵”求逆的“埃兰特”方法之C#源代码,《C#数值计算算法编程》源代码升级改进版

C#,码海拾贝(15)——“对称正定矩阵”的求逆和“托伯利兹矩阵”求逆的“埃兰特”方法之C#源代码,《C#数值计算算法编程》源代码升级改进版

对称正定矩阵

在线性代数中,正定矩阵的性质类似复数中的正实数。与正定矩阵相对应的线性算子是对称正定双线性形式。

正定矩阵的行列式恒为正;实对称矩阵A正定当且仅当A与单位矩阵合同;若A是正定矩阵,则A的逆矩阵也是正定矩阵;两个正定矩阵的和是正定矩阵;正实数与正定矩阵的乘积是正定矩阵。

对于n阶实对称矩阵A,下列条件是等价的:A是正定矩阵;A的一切顺序主子式均为正;A的一切主子式均为正;A的特征值均为正。

对于具体的实对称矩阵,常用矩阵的各阶顺序主子式是否大于零来判断其正定性;对于抽象的矩阵,由给定矩阵的正定性,利用标准型,特征值及充分必要条件来证相关矩阵的正定性。

In linear algebra, the properties of positive definite matrices are similar to positive real numbers in complex numbers. The linear operator corresponding to a positive definite matrix is a symmetric positive definite bilinear form.

The determinant of a positive definite matrix is always positive; Real symmetric matrix A is positive definite if and only if A is congruent with identity matrix; If A is a positive definite matrix, then the inverse matrix of A is also a positive definite matrix; The sum of two positive definite matrices is a positive definite matrix; The product of positive real numbers and positive definite matrices is a positive definite matrix.

For n-order real symmetric matrix A, the following conditions are equivalent: A is a positive definite matrix; All sequential principal sub equations of A are positive; All principal and sub formulas of A are positive; The eigenvalues of A are all positive.

For a specific real symmetric matrix, it is commonly used to determine its positivity by determining whether the order of the main and sub expressions of each order of the matrix is greater than zero; For abstract matrices, the positive definiteness of the given matrix is demonstrated using the canonical form, eigenvalues, and necessary and sufficient conditions.

对称正定矩阵的求逆

using System;namespace Zhou.CSharp.Algorithm
{/// <summary>/// 矩阵类/// 作者:周长发/// 改进:深度混淆/// https://blog.csdn.net/beijinghorn/// </summary>public partial class Matrix{/// <summary>/// 对称正定矩阵的求逆/// </summary>/// <param name="src">源矩阵</param>/// <returns>求逆是否成功</returns>public static bool InvertSsgj(Matrix src){int i, j, k, m;double w, g;// 临时内存double[] pTmp = new double[src.Columns];// 逐列处理for (k = 0; k <= src.Columns - 1; k++){w = src[0];if (Math.Abs(w) < float.Epsilon){return false;}m = src.Columns - k - 1;for (i = 1; i <= src.Columns - 1; i++){g = src[i * src.Columns];pTmp[i] = g / w;if (i <= m){pTmp[i] = -pTmp[i];}for (j = 1; j <= i; j++){src[(i - 1) * src.Columns + j - 1] = src[i * src.Columns + j] + g * pTmp[j];}}src[src.Columns * src.Columns - 1] = 1.0 / w;for (i = 1; i <= src.Columns - 1; i++){src[(src.Columns - 1) * src.Columns + i - 1] = pTmp[i];}}// 行列调整for (i = 0; i <= src.Columns - 2; i++){for (j = i + 1; j <= src.Columns - 1; j++){src[i * src.Columns + j] = src[j * src.Columns + i];}}return true;}}
}

托伯利兹矩阵

托伯利兹矩阵求逆的埃兰特方法

Toeplitz矩阵(diagonal-constant matrix),指矩阵中每条自左上至右下的斜线上的元素相同。

对于方阵,Toeplitz方阵可以描述为:任一条平行于主对角线的直线上的元素相同。
matlab中生成托普利兹矩阵的函数是toeplitz(x,y),它生成一个以x为第一列,y为第一行的托普利兹矩阵。这里x, y均为向量,两者不必等长。
toeplitz(x)用向量x生成一个对称的托普利兹矩阵。
例如:T=toeplitz(1:6)

Toeplitz matrix refers to a diagonal constant matrix in which the elements on each diagonal line from top left to bottom right are the same.

For a square matrix, a Toeplitz square matrix can be described as: the elements on any straight line parallel to the main diagonal are the same.

The function used in MATLAB to generate a Toplitz matrix is toeplitz (x, y), which generates a Toplitz matrix with x as the first column and y as the first row. Here, x and y are both vectors, and they do not need to be of equal length.

Toeplitz (x) generates a symmetric Toeplitz matrix using the vector x.

For example: T=toeplitz (1:6)

using System;namespace Zhou.CSharp.Algorithm
{/// <summary>/// 矩阵类/// 作者:周长发/// 改进:深度混淆/// https://blog.csdn.net/beijinghorn/// </summary>public partial class Matrix{/// <summary>/// 托伯利兹矩阵求逆的埃兰特方法/// </summary>/// <param name="src">源矩阵</param>/// <returns>求逆是否成功</returns>public static bool InvertTrench(Matrix src){int i, j, k;double a, s;// 上三角元素double[] t = new double[src.Columns];// 下三角元素double[] tt = new double[src.Columns];// 上、下三角元素赋值for (i = 0; i < src.Columns; ++i){t[i] = src.GetElement(0, i);tt[i] = src.GetElement(i, 0);}// 临时缓冲区double[] c = new double[src.Columns];double[] r = new double[src.Columns];double[] p = new double[src.Columns];// 非Toeplitz矩阵,返回if (Math.Abs(t[0]) < float.Epsilon){return false;}a = t[0];c[0] = tt[1] / t[0];r[0] = t[1] / t[0];for (k = 0; k <= src.Columns - 3; k++){s = 0.0;for (j = 1; j <= k + 1; j++){s = s + c[k + 1 - j] * tt[j];}s = (s - tt[k + 2]) / a;for (i = 0; i <= k; i++){p[i] = c[i] + s * r[k - i];}c[k + 1] = -s;s = 0.0;for (j = 1; j <= k + 1; j++){s = s + r[k + 1 - j] * t[j];}s = (s - t[k + 2]) / a;for (i = 0; i <= k; i++){r[i] = r[i] + s * c[k - i];c[k - i] = p[k - i];}r[k + 1] = -s;a = 0.0;for (j = 1; j <= k + 2; j++){a = a + t[j] * c[j - 1];}a = t[0] - a;// 求解失败if (Math.Abs(a) < float.Epsilon){return false;}}src[0] = 1.0 / a;for (i = 0; i <= src.Columns - 2; i++){k = i + 1;j = (i + 1) * src.Columns;src[k] = -r[i] / a;src[j] = -c[i] / a;}for (i = 0; i <= src.Columns - 2; i++){for (j = 0; j <= src.Columns - 2; j++){k = (i + 1) * src.Columns + j + 1;src[k] = src[i * src.Columns + j] - c[i] * src[j + 1];src[k] = src[k] + c[src.Columns - j - 2] * src[src.Columns - i - 1];}}return true;}}
}