Is the result of finding the inverse using the Matlab function INV and the MATLAB version of the neural network algorithm described in this article
Implemented in C/C ++
From the comparison of the results, the algorithm is good.
MATLAB source code
Function C = inverse_1 (a) <br/> learning_rate = 0.065; <br/> epoch = 2500; <br/> C = zeros (SIZE ()); <br/> I = eye (SIZE (a); <br/> for I = 1: epoch <br/> C = C + learning_rate * transpose () * (I-A * C); <br/> end <br/>
C source code
The source code is dependent on several other files related to matrix operations. Then I will post the complete program.
# Include <vector> <br/> # include <assert. h> <br/> # include "matrix. H "</P> <p> using namespace STD; </P> <p> // C is the inverse of, the original matrix <br/> static void _ initialize_c (Matrix & C) <br/>{< br/> assert (C. size ()! = 0); </P> <p> vect V (C. size (); <br/> for (unsigned int I = 0; I <v. size (); I ++) {<br/> C [I] = V; <br/>}< br/> // identity matrix <br/> static void _ initialize_ I (Matrix & I) <br/> {<br/> for (INT I = 0; I <I. size (); I ++) {<br/> I [I] [I] = 1; <br/>}< br/> matrix matrix_inverse_1 (const Matrix & mat) <br/>{< br/> assert (mat. size () = mat [0]. size (); </P> <p> int mat_size = mat. size (); </P> <p> Matrix Weight = matrix_mul (matrix_transpose (MAT), mat); <br/> matrix C (mat_size ); <br/> _ initialize_c (c); <br/> Matrix I = C; <br/> _ initialize_ I (I ); </P> <p> double learning_rate = 0.065; // learning rate <br/> int epoch = 2500; // training generation <br/> while (EPOCH --> 0) {<br/> C = C + learning_rate * matrix_transpose (MAT) * (I-mat * C); <br/>}< br/> return C; <br/>}