You are on page 1of 3

Jonathan P.

LaGrone Problem Statement (Inversing Matrices)

Final Project

Aero 220-500

Another matrix function that is in the program is the inversion of a matrix, using Gauss-Jordanian elimination. To use this method, you must have a square matrix (nxn). If you do not use a square matrix the inverse cannot be found of the matrix. To use gauss Jordanian method, you must also combine the original matrix with an identity matrix with 1s going from the top left corner of the matrix diagonally to the bottom right corner of the matrix. The rest of the identity matrix is zeros and is also a square with the same size as the initial matrix (nxn). Then, you combine the original square matrix with the identity matrix into one matrix, use elementary operations, and then solve the matrix for the inverse matrix. Test Case Matrix 1= 1 5 9 1 2 6 4 2 3 7 5 3 4 8 6 1

Inverse of Matrix 1= -.083 -1.25 .75 .333 -.083 .917 -.583 0 .167 -.333 .167 0 0 -.333 .667 -.333

Algorithm 1) void Matrixclass::Inverse(ofstream& outfile) //from the header file a. cout<<endl<<endl; b. Matrixclass d(height, width) //defines the parameters of each matrix c. Matrixclass b(height, width) d. for (int i=0; i<height; i++){ //for loops in relation to the parameters e. for (int j=0; j<height; j++){ f. d.matrix[i][j]=matrix[i][j]; i. if (i==j){ 1. b.matrix[i][j]=1; ii. else{b.matrix[i][j]=0;} //identity matrix g. double s=0; h. double t=0; i. for (int j=0; j<height; j++) j. for (int i=j; i<height; i++) i. if (d.matrix[i][j]!=0) 1. for (int k=0; k<height; k++) a. s=d.matrix[j][k] b. d.matrix[j][k]=d.matrix[i][k] c. d.matrix[i][k]=s d. s=b.matrix[j][k] e. b.matrix[j][k]=b.matrix[i][k]

b.matrix[i][k]=s //functions that relate the original matrix and the identity matrix ii. t=1/d.matrix[j][j]; k. for(int k=0;k<height;k++) i. d.matrix[j][k]=t*d.matrix[j][k] ii. b.matrix[j][k]=t*b.matrix[j][k] l. for(int L=0; L<height; L++) m. if(L!=j) i. t=(-1)*d.matrix[L][j] n. for(int k=0; k<height; k++) i. d.matrix[L][k]=d.matrix[L][k]+t*d.matrix[j][k] ii. b.matrix[L][k]=b.matrix[L][k]+t*b.matrix[j][k] //equations to find the inversion of the initial matrix into a new matrix using arrays with several parameters iii. break 2) b.display(outfile)

f.

You might also like