Question
H.W. #5 The code below is a working Gaussian elimination function. It returns the solution vector X to a system of linear equations AX=B. You
H.W. #5 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:
51 + 22 43 = 10
101 82 + 63 = 51
151 + 52 73 = 33
by finding the inverse of A and then using X=A-1B 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 -1A.
function X = Gauss_Elim(A,B) % %make sure B is in column form B=B(:); %determine size of coefficient matrix [nr,nc]=size(A); %build Augmented matrix Aug=[A B]; %Perform Gaussian Elimination without any error reducing row-swapping for col = 1:nc-1 %current column value being reduced to zero for row = col+1:nr %current row value being reduced to zero %identify factor to multiply by pivot row factor = -Aug(row,col)/Aug(col,col); %replace 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; for k = (i+1):nr summ=summ+A(i,k)*X(k); end X(i)=(B(i)-summ)/A(i,i); end X=X(:); %convert solution to column form
Also Attach a Pseudocode with this.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started