Reference no: EM1384111
Write a function that solves a system of linear equations or calculates the inverse of a matrix by Gauss-Jordan elimination. Your function should accept a matrix as an argument and return a matrix of the same dimension.
Note: Your function should be written to handle matrices of any size. Test your function with matrices of different sizes for which you know the solution to ensure that your function works correctly.
Use variable names that relate to their function and include comments that explain your program logic.
Do not use any built-in MATLAB functions except size(), input(), and zeros().
As example of what is expected from this function consider the following linear system:
3x + 2y + z = 11
2x + 3y +z = 13
x + y + 4z = 12
In this case you should pass into your function the following augmented matrix:
![2341_calculates the inverse of a matrix by Gauss-Jordan elimination.png](https://secure.expertsmind.com/CMSImages/2341_calculates%20the%20inverse%20of%20a%20matrix%20by%20Gauss-Jordan%20elimination.png)
After performing Gauss-Jordan elimination, your function should return the following reduced system:
![1107_calculates the inverse of a matrix by Gauss-Jordan elimination1.png](https://secure.expertsmind.com/CMSImages/1107_calculates%20the%20inverse%20of%20a%20matrix%20by%20Gauss-Jordan%20elimination1.png)
from which we can readily determine that x = 1, y = 3, z = 2.
Furthermore, if you pass a double augmented matrix such as
![1435_calculates the inverse of a matrix by Gauss-Jordan elimination2.png](https://secure.expertsmind.com/CMSImages/1435_calculates%20the%20inverse%20of%20a%20matrix%20by%20Gauss-Jordan%20elimination2.png)
Your function should return
![441_calculates the inverse of a matrix by Gauss-Jordan elimination3.png](https://secure.expertsmind.com/CMSImages/441_calculates%20the%20inverse%20of%20a%20matrix%20by%20Gauss-Jordan%20elimination3.png)
which solves the original equations
3x + 2y + z = 11
2x + 3y +z = 13
x + y + 4z = 12
as x = 1, y = 3, z = 2
and, at the same time, the equations
3x + 2y + z = -5
2x + 3y +z = -4
x + y + 4z = 9
as x = -2, y = -1, z = 3.
Additionally, if you pass to your function a square matrix on the left augmented by the identity matrix on the right, such as
![705_calculates the inverse of a matrix by Gauss-Jordan elimination4.png](https://secure.expertsmind.com/CMSImages/705_calculates%20the%20inverse%20of%20a%20matrix%20by%20Gauss-Jordan%20elimination4.png)
your function should return the identity matrix on the left and the inverse of the original square matrix on the right.