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 (e.g. x, x^2, x^3, etc.). these are evaluated over the range [-1,1]. beware of numerical precision issues for high degrees... example: figure; imagesc(constructpolynomialmatrix(100,0:3));
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 (e.g. x, x^2, x^3, etc.). 0010 % these are evaluated over the range [-1,1]. 0011 % beware of numerical precision issues for high degrees... 0012 % 0013 % example: 0014 % figure; imagesc(constructpolynomialmatrix(100,0:3)); 0015 0016 % do it 0017 f = []; 0018 temp = linspace(-1,1,n)'; 0019 for p=1:length(degrees) 0020 f = cat(2,f,temp .^ degrees(p)); 0021 end