In this part of the project you will create a function that

In this part of the project, you will create a function that returns an inverse of an invertible function A by implementing the row reduction algorithm. **Create the following functions in MATLAB: function D=inverses(A) which takes as an input an n x n matrix A. First, the function has to determine whether A is invertible (you may want to use the function rank to do that). If A is not invertible, the function has to return an empty matrix D = []; and terminates with a message \"Matrix A is not invertible\". If A is invertible, then the function reduces the matrix [A eye(n)] into the reduced echelon form and returns the matrix D that is the inverse of the matrix A. You can use a MATLAB built-in function rref for this part. **Type the functions inverses in your diary file. **Run the function D=inverses(A) on the given choices of the matrices A in (a)-(d). A = [4 -6 7 -1 0 1 -5 2 -7 11 10 3 -7 9 19 -1] A = [1 -3 2 -4 -3 9 -6 12 2 -1 4 2 -4 5 -3 7], A = magic(5) **Run a built-in MATLAB function inv on the matrices A for parts (c) and (d). % Write a comment in your diary file why the result obtained by using inv function is inaccurate for the matrix in part (d).

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.

 In this part of the project, you will create a function that returns an inverse of an invertible function A by implementing the row reduction algorithm. **Crea
 In this part of the project, you will create a function that returns an inverse of an invertible function A by implementing the row reduction algorithm. **Crea
 In this part of the project, you will create a function that returns an inverse of an invertible function A by implementing the row reduction algorithm. **Crea

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site