% generate data from the true model:
x = linspace(-2, 2, 100);
y = 2 * x.^2 - x + 3;

yn = y + 2*(rand(1, 100) - 0.5);  % add some noise

% solve the interpolation problem A*coef = y
% when the model is a 2nd degree polynomial
A = [ones(100,1), x', x'.^2];  % Vandermonde matrix
coef = pinv(A) * y';            % solution, no noise in y

coefn = pinv(A) * yn';          % solution, uniform noise in y

hold on;
plot(x, yn, 'b.');
plot(x, coef(1) + coef(2) .* x + coef(3) .* x.^2, 'k-');
plot(x, coefn(1) + coefn(2) .* x + coefn(3) .* x.^2, 'r-');
hold off;
