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

To compute the QR factorization of matrix A and solve the linear system Rx=b in MATLAB, you can use the following code:

main.m
% Given matrix A
A = magic(3);

% Given vector b
b = [1; 2; 3];

% Compute the QR factorization of A
[Q, R] = qr(A);

% Solve the linear system R*x = Q'*b
x = R \ (Q' * b);
173 chars
12 lines

The solution x will be the vector approximating the solution to the linear system R*x = Q'*b.

gistlibby LogSnag