In: Advanced Math
11.1 Determine the matrix inverse for the following system:
10x1 + 2x2 − x3 = −27
−3x1 −6x2 +2x3 = −61.5
x1 + x2 +5x3 = −21.5
Check your results by verifying that [A][A]-1 = [I ]. Do not use a pivoting strategy.
Calculate A^-1 using the LU decomposition of A. Use the Matlab lu command to perform the LU decomposition. Use the Matlab backslash \ operator to perform intermediate linear system solutions. Use Matlab matrix multiplication to verify that A^-1 was correctly calculated.
MATLAB Code:
close all
clear
clc
format short
% Given system of equations when written in matrix form, Ax =
b
A = [10 2 -1; -3 -6 2; 1 1 5];
b = [-27 -61.5 -21.5]';
% and x = [x1; x2; x3]
[L,U] = lu(A); % LU Decomposition
% A = LU => A_inverse = inverse(LU) = U_inverse *
L_inverse
A_inv = inv(U)*inv(L);
disp('Inverse of A using LU decomposition ='), disp(A_inv)
disp('and A times inverse(A) obtained above ='),
disp(A*A_inv)
disp('which is an identity matrix, verifying that the obtained
inverse is correct.')
x = A\b; % Solve the linear system
fprintf('\nSolution to the system, x =\n'), disp(x)
Output:
Inverse of A using LU decomposition =
0.1107 0.0381 0.0069
-0.0588 -0.1765 0.0588
-0.0104 0.0277 0.1869
and A times inverse(A) obtained above =
1.0000 0.0000 0
0.0000 1.0000 0.0000
-0.0000 0.0000 1.0000
which is an identity matrix, verifying that the obtained inverse is
correct.
Solution to the system, x =
-5.4792
11.1765
-5.4394