Open in the MATLAB editor: f08cg_example
function f08cg_example fprintf('f08cg example results\n\n'); a = [-0.57, -1.28, -0.39, 0.25; -1.93, 1.08, -0.31, -2.14; 2.3, 0.24, 0.4, -0.35; -1.93, 0.64, -0.66, 0.08; 0.15, 0.3, 0.15, -2.13; -0.02, 1.03, -1.43, 0.5]; 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 QL factorization of a [a, tau, info] = f08ce(a); % Compute C = (C1) = (Q^T)*b % (C2) [c, info] = f08cg( ... 'Left', 'Transpose', a, tau, b); % Compute least-squares solutions by backsubstitution in L*X = C2 [b, info] = f07te( ... 'Lower', 'No Transpose', 'Non-Unit', a(3:6,:), c(3:6,:)); if (info > 0) fprintf('The lower triangular factor, L, of A is singular,\n'); fprintf('the least squares solution could not be computed.\n'); else % Print least-squares solutions [ifail] = x04ca( ... 'General', ' ', b, 'Least-squares solution(s)'); % Compute and print estimates of the square roots of the residual % sums of squares rnorm = zeros(2,1); for j=1:2 rnorm(j) = norm(c(1:2,j)); end fprintf('\nSquare root(s) of the residual sum(s) of squares\n'); fprintf('\t%11.2e %11.2e\n', rnorm(1), rnorm(2)); end
f08cg example results Least-squares solution(s) 1 2 1 1.5339 -1.5753 2 1.8707 0.5559 3 -1.5241 1.3119 4 0.0392 2.9585 Square root(s) of the residual sum(s) of squares 2.22e-02 1.38e-02