Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

49. Test the inverse formula of Theorem 8 for a random 4 x 4 matrix A. Use MatLa

ID: 3283805 • Letter: 4

Question

49. Test the inverse formula of Theorem 8 for a random 4 x 4 matrix A. Use MatLab to compute the Then compute B-invA, adjA cofactors of the 3 x 3 submatrices, construct the adjugate, and set B- where invA is the inverse of matrix A as computed by MatLab. use floating point arithmetic with the maximum number of decimal places and report your results. 50. Test Cramer's rule for a random 4 × 4 matrix A and a random 4 x 1 vector b. Compute each entry in the soution of Ax b, and compare these entries with the entries of A-1b. Write the commands for your program that uses Cramer's rule to prduce the second entry of >x.

Explanation / Answer

49. MATLAB CODE

clc
clear all
format long
A=[1 2 1 0; 0 3 1 1;-1 0 3 1; 3 1 2 0]
%%%%%%% Finding Cofactor Matrix of the gicen matrix A %%%%%%%%
M = ones(4,4); %preallocates 4 x 4 cofactor matrix   
A_temp=A; %creating temporary matrix equal to input
for i = 1:4
for k = 1:4
A_temp([i],:)=[]; %removing ith row
A_temp(:,[k])=[]; %removing kth row
M(i,k) = ((-1)^(i+k))*det(A_temp); %computation of cofactor element
A_temp=A; %reset elements of temporary matrix to input elements
end  
end
cofA=M % cofactor matrix as output variable
AdjA=transpose(cofA) % Computes Adjoint matrix of A
DetA=det(A) % Computes Determinant of matrix A

if (DetA==0)
disp('Inverse does not exist') % to desiply invrese not possible because A is singular
else
invA=AdjA/DetA % Computes inverse of matrix A
end

%%% Finding inverse direct by MATLAB %%%%%%%%
B=inv(A) % this compute the inverse of A directly if A is non-singular

OUTPUT

A =

1 2 1 0
0 3 1 1
-1 0 3 1
3 1 2 0


cofA =

-8 8 8 -32
3 1 -5 18
-3 -1 5 -2
7 -3 -1 10


AdjA =

-8 3 -3 7
8 1 -1 -3
8 -5 5 -1
-32 18 -2 10


DetA =

16


invA =

-0.500000000000000 0.187500000000000 -0.187500000000000 0.437500000000000
0.500000000000000 0.062500000000000 -0.062500000000000 -0.187500000000000
0.500000000000000 -0.312500000000000 0.312500000000000 -0.062500000000000
-2.000000000000000 1.125000000000000 -0.125000000000000 0.625000000000000


B =

-0.500000000000000 0.187500000000000 -0.187500000000000 0.437500000000000
0.500000000000000 0.062500000000000 -0.062500000000000 -0.187500000000000
0.500000000000000 -0.312500000000000 0.312500000000000 -0.062500000000000
-2.000000000000000 1.125000000000000 -0.125000000000000 0.625000000000000

5. CODE FOR CRAMER'S RULE

clc
clear all
format long
A=[1 2 1 0; 0 3 1 1;-1 0 3 1; 3 1 2 0]
b=[1; 2; 3; 4]

DetA=det(A);
if A==0
error('No Solution')
elseif DetA==0
error('No Solution')
end
for i=1:4
Aug=A;  
Aug(:,i)=b; % This commond finds augmented matrix by rplacing 1st column by b, then 2nd column etc..   
x(i)=(det(Aug)/DetA); % Compute each entry in Ax=b
end
sol_by_cr=transpose(x) %%% Displys all entries in solution of Ax=b by Cramer's
X=inv(A)*b %%% Computes dierct solution using A^-1*b
Entry_2=x(2) %%% Code for for producing second entry

OUTPUT

A =

1 2 1 0
0 3 1 1
-1 0 3 1
3 1 2 0


b =

1
2
3
4


sol_by_cr =

1.062500000000000
-0.312500000000000
0.562500000000000
2.375000000000000


X =

1.062500000000000
-0.312500000000000
0.562500000000000
2.375000000000000


Entry_2 =

-0.312500000000000

OUTPUT

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote