We have seen how easy it is to come up with a interpolating polynomial in the monomial basis. The technique does however have some downfalls.
The simple code attached allows you to play around with this kind of interpolation. You must define the interval, function and interpolation points.  As the plot shows, the polynomial grows very large close to the endpoints of the interval. One of the reasons for this is that we chose equally distanced interpolation points.
There exist better choices of interpolation points, but it is not always the case that you may chose the points to be used, e.g. when using table values. Try increasing the number of interpolation points and see what happens. DOWNLOAD M-FILE HERE.

I have yet to find out how to make good looking plots  MATLAB. If I export using 600dpi, graph looks fine when viewed in full-size, but when I shrink it to fit wordpress it does not look good at all. The figure in this post is exported using 150dpi, and it is not pretty. Any hints are greatly appreciated!

% Polynomial interpolation using monomial basis.
% interpolation_monomial.m

function [] = interpolation_monomial(x,y,x_interval)
m = length(x);

% Create Vandermonde matrix.
V = zeros(m,m);

for i = 1:m
 V(i,:) = x(i).^(0:m-1);

% Find coefficients a_0,a_1,...,a_n.
a = V\y';

% flipud() reverses the column vector a so it may be used correctly in
% polyval().
h1 = plot(x_interval,polyval(flipud(a),x_interval));
set(h1,'LineStyle','- -','LineWidth',1.5,'Color','Black');

% Testing interpolation_monomial.m

x_interval = linspace(0,1,1000);
f = @(x) cos(40.*x);

hold on;
h1 = plot(x_interval,f(x_interval));

% Choose n+1 points on function.
x = 0:0.1:1;
y = f(x);



fh = figure(1);