%% clear format compact %% % The functions $\sin^2(t)$, $\cos^2(t)$, and $1$ are linearly dependent; % the following matrix is ill-conditioned. beta = 1 + 4.5e-8; t = linspace(0,3,400)'; A = [ sin(t).^2, cos(beta*t).^2, t.^0 ]; kappa = cond(A) %% % Now we set up an artificial linear least squares problem with a known % exact solution that actually makes the residual zero. x = [1; 2; 1]; b = A*x; %% % If we formulate and solve via the normal equations, we get a large % relative error. N = A'*A; x_NE = N\(A'*b); observed_err = norm(x_NE - x)/norm(x)