In this part of the project you will create a function that
Solution
%% Inverse finding
function D=inverses(A)
detA=det(A);
if detA==0
disp(\' A is not an Invertible Matrix\');
D=[];
else
sizeofA=size(A);
B=[A eye(sizeofA)];
temp=rref(B);
D=temp(:,sizeofA+1:2*sizeofA);
end
%% MATLAB code to run
clc;
close all;
clear all;
%%
disp(\'Solution for a\');
A=[4 0 -7 -7
-6 1 11 9
7 -5 10 19
-1 2 3 -1];
disp(\'Using inverses function\');
User_Defined_inv_func=inverses(A);
disp(User_Defined_inv_func);
disp(\'Using MATLAB function inv()\');
MATLAB_inv_func=inv(A);
disp(MATLAB_inv_func);
%% Solution for b
disp(\'Solution for b\');
A=[1 -3 2 -4
-3 9 -1 5
2 -6 4 -3
-4 12 2 7];
disp(\'Using inverses function\');
User_Defined_inv_func=inverses(A);
disp(User_Defined_inv_func);
disp(\'Using MATLAB function inv()\');
MATLAB_inv_func=inv(A);
disp(MATLAB_inv_func);
%% Solution for c
disp(\'Solution for c\');
A=magic(5);
disp(\'Using inverses function\')
User_Defined_inv_func=inverses(A);
disp(User_Defined_inv_func);
disp(\'Using MATLAB function inv()\');
MATLAB_inv_func=inv(A);
disp(MATLAB_inv_func);
%% Solution for d
disp(\'Solution for d\');
A=magic(4);
disp(\'Using inverses function\')
User_Defined_inv_func=inverses(A);
disp(User_Defined_inv_func);
disp(\'Using MATLAB function inv()\')
MATLAB_inv_func=inv(A);
disp(MATLAB_inv_func);
%% Program terminates here.
OUTPUT:
Solution for a
Using inverses function
-19 -14 0 7
-549 -401 -2 196
267 195 1 -95
-278 -203 -1 99
Using MATLAB function inv()
-19.0000 -14.0000 -0.0000 7.0000
-549.0000 -401.0000 -2.0000 196.0000
267.0000 195.0000 1.0000 -95.0000
-278.0000 -203.0000 -1.0000 99.0000
Solution for b
Using inverses function
A is not an Invertible Matrix
Using MATLAB function inv()
Warning: Matrix is singular to working precision.
> In Run_inverse_func at 27
Inf Inf Inf Inf
Inf Inf Inf Inf
Inf Inf Inf Inf
Inf Inf Inf Inf
Solution for c
Using inverses function
-0.0049 0.0512 -0.0354 0.0012 0.0034
0.0431 -0.0373 -0.0046 0.0127 0.0015
-0.0303 0.0031 0.0031 0.0031 0.0364
0.0047 -0.0065 0.0108 0.0435 -0.0370
0.0028 0.0050 0.0415 -0.0450 0.0111
Using MATLAB function inv()
-0.0049 0.0512 -0.0354 0.0012 0.0034
0.0431 -0.0373 -0.0046 0.0127 0.0015
-0.0303 0.0031 0.0031 0.0031 0.0364
0.0047 -0.0065 0.0108 0.0435 -0.0370
0.0028 0.0050 0.0415 -0.0450 0.0111
Solution for d
Using inverses function
0 -0.1544 0.1838 0.0294
0 0.8162 -0.2574 -0.4412
0 -0.7206 0.1912 0.4706
1.0000 3.0000 -3.0000 -1.0000
Using MATLAB function inv()
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.306145e-17.
> In Run_inverse_func at 45
1.0e+14 *
0.9382 2.8147 -2.8147 -0.9382
2.8147 8.4442 -8.4442 -2.8147
-2.8147 -8.4442 8.4442 2.8147
-0.9382 -2.8147 2.8147 0.9382
The value in case of d is different because singular value is not scaled properly.


