function [normPR,normQR]=hw3_2_2(n) % kinda covers problems 2.2 from hw3 and 2.3 from hw4. % the size of the matrix, n, is the input. % normPR=norm(P-R) and normQR=norm(Q-R) and the outputs. % you can write another script to run through different values of n % just supress the the other disp commands in this file by commenting them out format short g A=hilb(n) P=inv(A'*A) Q=inv(A)*inv(A)' disp('P and Q look the same but...Q-P is:') disp(Q-P) % R is the exact inverse of A*A', i.e., computed algebraicly not numerically R=invhilb(n)*invhilb(n)' fprintf('Distance from P to R: %6.2f \nand the distance from Q to R is: %6.2f \n',norm(P-R),norm(Q-R)) % so Q is "closer" to R than P is, but there is still some error in the % computation...why? Let's look at condition numbers fprintf('condition number of A: %6.2f \n',cond(A)) fprintf('condition number of A''*A: %6.2f',cond(A'*A)) format short % so it's MUCH more difficult so solve the system A'*A*x=b than it is to solve % the system A*x=b. i.e. it's harder to compute inv(A'*A) accurately than it is % to just compute inv(A). So Q has less error than P since Q only inverts A and % P directly inverts A'*A