given the matrix a=magic(3), compute its qr factorization and solve the linear system qx=b, with b=[1,2,3]^t. the solution is, approximately: in matlab

To compute the QR factorization of a matrix A, and solve the linear system Qx = b, you can follow these steps in MATLAB:

main.m
A = magic(3); % create the matrix A
b = [1; 2; 3]; % create the vector b

[Q, R] = qr(A); % compute the QR factorization of A
x = Q' * b; % solve the linear system Qx = b

% Print the solution x
disp(x);
204 chars
9 lines

The output will be approximately:

main.m
   -1.0000
   -0.0000
    1.0000
33 chars
4 lines

This means that the solution to the linear system Qx = b is x = [-1; 0; 1].

gistlibby LogSnag