Created
January 27, 2013 19:49
-
-
Save zdwolfe/4650078 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Zachary Wolfe | |
% [email protected] | |
% CMPSC 456 SPR 2013 | |
function [aQR, rQR, aMGS, rMGS, aCHOL, rCHOL] = fit() | |
t = 0:0.05:1; | |
V = vander(t); | |
X = V(:,17:21); | |
b = sin(pi*t); | |
b = b'; % make b a column vector | |
%mQ, mR are Q,R from Matlab's QR factorization | |
[mQ, mR] = qr(X); | |
[aQR, rQR] = mgs_solve(mQ, mR,b); | |
%gQ, gR are from modified Gram - Schmidt defined in mgs.m | |
[gQ, gR] = mgs(X); | |
[aMGS,rMGS]= mgs_solve(gQ, gR,b); | |
% To solve least squares using cholesky | |
% First find the cholesky decomposition of X'X, then solve | |
% cR'cR*yLS = X'b | |
cR = chol(X'*X); | |
aCHOL = (X'*b)\(cR'*cR); | |
aCHOL = inv(cR'*cR)*(X'*b); | |
rCHOL = b - X*aCHOL; | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment