/// 矩阵的转置 public bool MatrixInver(double[,] a, ref double[,] b) { if (a.GetLength(0) != b.GetLength(1) || a.GetLength(1) != b.GetLength(0)) return false; for (int i = 0; i < a.GetLength(1); i++) for (int j = 0; j < a.GetLength(0); j++) b[i, j] = a[j, i]; return true; } /// 矩阵的逆 public bool MatrixOpp(double[,] a, ref double[,] b) { double X = MatrixSurplus(a); if (X == 0) return false; X = 1 / X; double[,] B = new double[a.GetLength(0), a.GetLength(1)]; double[,] SP = new double[a.GetLength(0), a.GetLength(1)]; double[,] AB = new double[a.GetLength(0), a.GetLength(1)]; for (int i = 0; i < a.GetLength(0); i++) for (int j = 0; j < a.GetLength(1); j++) { for (int m = 0; m < a.GetLength(0); m++) for (int n = 0; n < a.GetLength(1); n++) B[m, n] = a[m, n]; { for (int x = 0; x < a.GetLength(1); x++) B[i, x] = 0; for (int y = 0; y < a.GetLength(0); y++) B[y, j] = 0; B[i, j] = 1; SP[i, j] = MatrixSurplus(B); AB[i, j] = X * SP[i, j]; } } MatrixInver(AB, ref b);
/// 矩阵的转置
public bool MatrixInver(double[,] a, ref double[,] b)
{
if (a.GetLength(0) != b.GetLength(1) || a.GetLength(1) != b.GetLength(0))
return false;
for (int i = 0; i < a.GetLength(1); i++)
for (int j = 0; j < a.GetLength(0); j++)
b[i, j] = a[j, i]; return true;
} /// 矩阵的逆
public bool MatrixOpp(double[,] a, ref double[,] b)
{
double X = MatrixSurplus(a);
if (X == 0) return false;
X = 1 / X; double[,] B = new double[a.GetLength(0), a.GetLength(1)];
double[,] SP = new double[a.GetLength(0), a.GetLength(1)];
double[,] AB = new double[a.GetLength(0), a.GetLength(1)]; for (int i = 0; i < a.GetLength(0); i++)
for (int j = 0; j < a.GetLength(1); j++)
{
for (int m = 0; m < a.GetLength(0); m++)
for (int n = 0; n < a.GetLength(1); n++)
B[m, n] = a[m, n];
{
for (int x = 0; x < a.GetLength(1); x++)
B[i, x] = 0;
for (int y = 0; y < a.GetLength(0); y++)
B[y, j] = 0;
B[i, j] = 1;
SP[i, j] = MatrixSurplus(B);
AB[i, j] = X * SP[i, j];
}
}
MatrixInver(AB, ref b);
return true;
}
myMatrix.Invert();
谢谢!
这样就把数组转置了。