C # inverse matrix,
The inverse matrix is obtained using the transformation of the unit matrix determinant. The source code is shown as follows:
Public static double [,] Inverse (double [,] Array) {int m = 0; int n = 0; m = Array. getLength (0); n = Array. getLength (1); double [,] array = new double [2 * m + 1, 2 * n + 1]; for (int k = 0; k <2 * m + 1; k ++) // initialize the Array {for (int t = 0; t <2 * n + 1; t ++) {array [k, t] = 0.00000000 ;}}for (int I = 0; I <m; I ++) {for (int j = 0; j <n; j ++) {array [I, j] = Array [I, j] ;}}for (int k = 0; k <m; k ++) {for (int T = n; t <= 2 * n; t ++) {if (t-k) = m) {array [k, t] = 1.0 ;} else {array [k, t] = 0 ;}}// obtain the inverse matrix for (int k = 0; k <m; k ++) {if (array [k, k]! = 1) {double bs = array [k, k]; array [k, k] = 1; for (int p = k + 1; p <2 * n; p ++) {array [k, p]/= bs ;}} for (int q = 0; q <m; q ++) {if (q! = K) {double bs = array [q, k]; for (int p = 0; p <2 * n; p ++) {array [q, p]-= bs * array [k, p] ;}} else {continue ;}} double [,] NI = new double [m, n]; for (int x = 0; x <m; x ++) {for (int y = n; y <2 * n; y ++) {NI [x, y-n] = array [x, y] ;}} return NI ;}
Test code:
Static void Main (string [] args) {double [,] a = new double [3, 3] {1, 2, 3}, {2, 2, 1 }, {3, 4, 3 }}; // test array double [,] dReturn = Inverse (a); for (int I = 0; I <. getLength (0); I ++) {for (int j = 0; j <. getLength (1); j ++) {Console. write (dReturn [I, j] + "\ t");} Console. writeLine ();} Console. readKey ();}
Test result display: