% monomial basis functions for interpolation
% n=3 data points: 
% t:  -2   0   1
% y: -27  -1   0
% Example 7.1 on p. 314 of Heath
% monomial.m
% Ming Leung, 12/27/02

clear all; hold off;
tV=[-2  0   1]';
yV=[-27  -1   0]';
n=length(tV); AS=ones(n,n);
for i=2:n, AS(:,i)=tV.*AS(:,i-1); end,
xV=AS\yV, 
AS, xV,     % Display matrix and coefficients
x_plot=-3:0.1:2;
plot(x_plot,polyval(xV(n:-1:1),x_plot));
hold on; plot(tV,yV,'r*');
xlabel('t'); ylabel('y');
title('Interpolation using monomials');