Open in the MATLAB editor: f08ac_example
function f08ac_example fprintf('f08ac example results\n\n'); % Minimize ||Ax - b|| using recursive QR for m-by-n A and m-by-p B m = int64(6); n = int64(4); p = int64(2); a = [-0.57, -1.28, -0.39, 0.25; -1.93, 1.08, -0.31, -2.14; 2.30, 0.24, 0.40, -0.35; -1.93, 0.64, -0.66, 0.08; 0.15, 0.30, 0.15, -2.13; -0.02, 1.03, -1.43, 0.50]; b = [-2.67, 0.41; -0.55, -3.10; 3.34, -4.01; -0.77, 2.76; 0.48, -6.17; 4.10, 0.21]; % Compute the QR Factorisation of A [QR, T, info] = f08ab(n,a); % Compute C = (C1) = (Q^T)*B [c1, info] = f08ac(... 'Left', 'Transpose', QR, T, b); % Compute least-squares solutions by backsubstitution in R*X = C1 [x, info] = f07te(... 'Upper', 'No Transpose', 'Non-Unit', QR, c1, 'n', n); % Print least-squares solutions disp('Least-squares solutions'); disp(x(1:n,:)); % Compute and print estimates of the square roots of the residual % sums of squares for j=1:p rnorm(j) = norm(x(n+1:m,j)); end fprintf('\nSquare roots of the residual sums of squares\n'); fprintf('%12.2e', rnorm); fprintf('\n');
f08ac example results Least-squares solutions 1.5339 -1.5753 1.8707 0.5559 -1.5241 1.3119 0.0392 2.9585 Square roots of the residual sums of squares 2.22e-02 1.38e-02