Matrix invert

Author: Song Li

##AIM##
This program is used to generate, invert matrix. Just use row addups and swaps rows randomly to generate a invertable matrix.

##USAGE##

• Invert Matrix: To use the invert function, users need to input the Maxtric File right after the program. Here is an example: $$./debug/invert~./debug/input$$
• Generate Matrix: To use the generate function, users need to input $-g$ after the program and the size of matrix after the $-g$. Here is an example:
$$./debug/invert~-g~3$$
This command will generate a $3*3$ matrix, and this maxtrix will be output to the terminal and stored in the $./debug/generate$ file at the same time.
##COMPILE##
Just use $make$ in the root dir of this program to compile this program. I didn’t modify the $Makefile$
##FILE STRUCTURE##
• Makefile
• debug/: contains the runable program and generated matrix
• matrix1-sol315.txt
• matrix2-sol315.txt
• object/
• pivoting-sol315.txt
• source/main.cpp: main code of this program
• source/StdAfx.cpp: useless
• source/parseMatrix.cpp: this code is used to input and output the matrix
• source/parseMatrix.h: head file of paraseMatrix.cpp
##RESULT##
Most of the result will be output directely in the terminal. The generated matrix will be output in both terminal and $/debug/generate$ file.
##DESIGN##
In this part, I mainly talk about how I generate a matrix which is invertable.
Firstly, I generate a matrix which is random double numbers in the diagonal line, and other numbers are all 0. Like this:
$$\begin{bmatrix} 1.231 & 0.000 & 0.000 & 0.000 \\ 0.000 & 1.002 & 0.000 & 0.000 \\ 0.000 & 0.000 & 1923.412 & 0.000 \\ 0.000 & 0.000 & 0.000 & 0.023 \\ \end{bmatrix}$$

After that, I randomly pick a line, use a random double number times every number of this line, and add it to another random line.If I pick line 2 and number 2, and add this line to the 4th line. The result will be like
$$\begin{bmatrix} 1.231&0.000&0.000&0.000 \\ 0.000&1.002&0.000&0.000 \\ 0.000&0.000&1923.412&0.000 \\ 0.000&2.004&0.000&0.023 \\ \end{bmatrix}$$
Some times later, we can get a random matrix. Generately speaking, we can get every matrix in this way.

Main function code is here. The whole project can be downloaded from the link at the begining of this blog.

Contents