% Matlab diary from cs111, Nov 7 2007. % % This is what I typed in class. % % Type it into Matlab yourself to % reproduce the output I showed. load censusdata whos plot(t,y,'o') X = [ t.^2 t ones(11,1)] y beta = X \ y hold on plot(t, X*beta, 'r') warning on n = length(y) X format long X X(:,7) clc format short size(X) beta = X \ y rank(X) hold on plot(t, X*beta, 'k') X t s = (t - 1950) s = (t - 1950) / 50 X = [s.^6 s.^5 s.^4 s.^3 s.^2 s ones(11,1)] rank(X) beta = X \ y plot(t, X*beta, 'r') censusgui X = [ t ones(n,1) ] y logy = log(y) beta = X \ log(y) lambda = beta(1) k = exp(beta(2)) plot(t,y,'o') hold on plot(t, k * exp(lambda * t)) X = [ 1 2 ; 3 4 ; 5 6] y = [1 ; 2 ; 4] beta = X \ y % This is how I plotted the three lines t = -1:.1:3 s1 = (y(1)-X(1,1)*t)/X(1,2); s2 = (y(2)-X(2,1)*t)/X(2,2); s3 = (y(3)-X(3,1)*t)/X(3,2); plot(t,s1);hold on; plot(t,s2,'r') plot(t,s3,'k') y X [Q,R] = qr(X) Q' Q * Q' Q' * Q cond(Q) diary off