% create a portion of a Vandermonde matrix for least squares approximation
% (first n columns of a vander matrix where n-1 is the order of polynomial

%     q         f(q)*255
%    0.011000   23.757634
%    0.021000   44.856354
%    0.048000   70.447514
%    0.079000   90.480663
%    0.126000  116.176796
%    0.185000  140.685083
%    0.264000  171.232044
%    0.358000  193.215470
%    0.472000  216.505525
%    0.622000  233.182320
%    0.733000  239.433702
%    0.893000  246.718232

q=[.011; .021; .048; .079; .126; .185; .264; .358; .472; .622; .733; .893];
f=[23.757634;44.856354;70.447514;90.480663;116.176796;140.685083;171.232044;193.215470;216.505525;233.182320;239.433702;246.718232]/255;

%V=[q.*q q ones(size(q))]; % vandermonde matrix

% for squadratic comparametric eq'n, we need inverse (reverse roles x and y):
V=[f.*f.*f f.*f f ones(size(f))]; % vandermonde matrix

%compute the least squares approximation
%coeffs = (inv(V'*V)*V')*f;

%coeffs=pinv(V)*f;
coeffs=pinv(V)*q;
a=coeffs(1)
b=coeffs(2)
c=coeffs(3)
d=coeffs(4)

