Question: use matlab to solve The code below is a working Gaussian elimination function. It returns the solution vector X to a system of linear equations
The code below is a working Gaussian elimination function. It returns the solution vector X to a system of linear equations AX=B. You are to create a new function that employs matrix inversion to find the inverse of any size square coefficient matrix A. Use this function to solve the following system: 5X, + 2x2 - 4x3 = -10 10X, -8X2 + 6X2 = 51 15X+ 5X2-7X3 = 33 by finding the inverse of A and then using X=AB in the main program. Present both the inverse of A and the solution for X1, X2, X3 as output. Also show that your solution for the inverse of A is correct by showing the result of A'A. function X = Gauss Elim (A,B) Smake sure Bis in column form BOB(:); determine size of coefficient matrix [nr, nc)=size (A); build Augmented matrix Aug=[AB]: Perform Gaussian Elimination without any error reducing row-swapping for col = 1:nc-1 Scurrent column value being reduced to zero for row - col +1:nr current row value being reduced to zero Sidentify factor to multiply by pivot row factor = -Aug (row, col) /Aug (col, col); Sreplace whole row with new reduced row Aug (row, :) - Aug (col,:) *factor+Aug (row, :); end end Reduce Augmented matrix back into A and B A=Aug (:,1:nc); B-Aug (: , nc+1); Perform back substitution on A and B for i = nr:-1:1 summ=0; fork - (i+1): summ=summ+A(i, k) *X (k); end x(i)-(B(i)-summ) /A(i, i); end X=X(:); $convert solution to column form
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
