Matlab/Linear Algebra help. Hello, I have the following problem and need help. P
ID: 3210023 • Letter: M
Question
Matlab/Linear Algebra help.
Hello,
I have the following problem and need help. Please see photo attached.
Let A and B be two 5 x 5 matrices with random entries between 0 and 1 . Test whether (A +15)(A-Is) = A2-15, where 15-diag(1, 1, 1, 1, 1) E R5,5 . The best way to do this is to compute (A + Is) (A Is) (A2 - Is) and check if it is the zero matrix. ·Test whether (A + B) (A-B) A2-B2 In homework 2 you were asked to solve the system Ax b with 31 -8 11 11 6 25 13 using the rref command and print on screen the error vector Ax - b, and compute its norm norm (A*x-b). Compare this error to the error you obtain when using the "backslash" operator to solve the system above.Explanation / Answer
Homework 1:
A=rand(5);% we use rand to create matrix with random entries between 0 and 1
B=rand(5);
% given I5 is a diagonal matrix with diagonal elements [1,1,1,1,1]
I5=diag([1, 1,1,1,1]);
result=(A+I5)*(A-I5)-(A*A-I5)
check=isequal(result,zeros(5));% checks whether result is a zero matrix or not
if check==1
test='true'
else
test='false'
end
result2=(A+B)*(A-B)-(A*A-B*B)
check2=isequal(result2,zeros(5));%checks whether result is a zero matrix or not
if check2==1
test2='true'
else
test2='false'
end
ouput:
result =
1.0e-15 *
0.1110 0 -0.2220 -0.2220 0.1110
0 0 0 0.2220 0.2220
0 0 0.2220 -0.2220 -0.1110
0 0 0 -0.2220 0
0 0 0.2220 0 0
test =
false
result2 =
0.3049 1.1886 0.3702 1.4689 0.2340
-0.4369 0.2841 -0.6876 0.2570 -0.3083
-0.6002 -0.1470 -0.6067 0.1079 -0.5107
-0.2936 0.3645 -0.0603 0.5142 -0.1982
-0.0336 -0.0360 0.0290 0.5402 -0.4964
test2 =
false
Note: Theoretically test1 is true and the result should be a zero matrix but we are dealing with MATLAB which operates on floating point arithmetic rather than actual arithmetic which has limited precision . so we got the result as false. To get rid of it we need to round off the result to 4 digits using the command -- round(result,4)... wherever we need the result.
Homework 2:
A=[31 -8 11;-8 15 -6;11 -6 25];
b=[8;-4;13];
aug=[A b];% creating augmented matrix
s=rref(aug);% reduced row echelon form of augmented matrix
x=s(:,4);% result for x 4th column of rref of augmented matrix gives us the result
error=A*x-b % error vector
mat_norm=norm(error);% find norm of error vector
x2=A;% solving the system of equations using backslash operator or mldivide
error2=A*x2-b;% error vector using solutions through backslash operator
check=isequal(error,error2);
if check==1
test='true'
else
test='false'
end
ouput:
error =
1.0e-04 *
-0.0991
0.1261
-0.7058
error2 =
1.0e-14 *
0
0
-0.1776
test =
false