% this matlab script is a demonstration on the use of 
% the polyinterp function

close all 
clear all

% create data set
x_k = 0:3
y_k = [-5 -6 -1 16]

% create a fine set of points at which to evaluate the interpolant
x = -0.25:0.01:3.25;

% use polyinterp to evaluate the corresponding values of the interpolant
y = polyinterp(x_k,y_k,x);

% plot the results
plot(x_k,y_k,'o',x,y,'-')

% polyinterp also works correctly with symbolic variables
symbolicX = sym('x');

% this produces a rearrangement of the Lagrange polynomial
P = polyinterp(x_k,y_k,symbolicX);
pretty(P)

% if we simplify it, we get the power form
P = simplify(P)