function f = constructpolynomialmatrix(n,degrees) <n> is the number of points <degrees> is a vector of polynomial degrees return a matrix of dimensions <n> x length(<degrees>) with polynomials in the columns. each column is orthogonalized with respect to all of the earlier columns and then made unit-length. please see the code for the exact details. beware of numerical precision issues for high degrees... history: - 2014/07/31 - now, we orthogonalize and make unit length. this changes previous behavior! example: X = constructpolynomialmatrix(100,0:3); figure; subplot(1,2,1); imagesc(X); subplot(1,2,2); imagesc(X'*X);
0001 function f = constructpolynomialmatrix(n,degrees) 0002 0003 % function f = constructpolynomialmatrix(n,degrees) 0004 % 0005 % <n> is the number of points 0006 % <degrees> is a vector of polynomial degrees 0007 % 0008 % return a matrix of dimensions <n> x length(<degrees>) 0009 % with polynomials in the columns. each column is orthogonalized 0010 % with respect to all of the earlier columns and then made 0011 % unit-length. please see the code for the exact details. 0012 % beware of numerical precision issues for high degrees... 0013 % 0014 % history: 0015 % - 2014/07/31 - now, we orthogonalize and make unit length. 0016 % this changes previous behavior! 0017 % 0018 % example: 0019 % X = constructpolynomialmatrix(100,0:3); 0020 % figure; subplot(1,2,1); imagesc(X); subplot(1,2,2); imagesc(X'*X); 0021 0022 % do it 0023 f = []; 0024 temp = linspace(-1,1,n)'; 0025 for p=1:length(degrees) 0026 0027 % construct polynomial 0028 polyvector = temp .^ degrees(p); 0029 0030 % orthogonalize with respect to earlier polynomials and make unit length 0031 polyvector = unitlength(projectionmatrix(f)*polyvector); 0032 0033 % record 0034 f = cat(2,f,polyvector); 0035 0036 end