p=poly([4,5])
%this command creates a polynomial whose roots are 4 and 5,
%i.e. it creates the polynomial (x-4)(x-5). It is represented by
%its list of coefficients, i.e. [1, -9, 20].
polyval(p,2)
%this calculates the actual value of the polynomial p at the 
%point x=2. The answer in this case is (2-4)(2-5), i.e. 6
polyval(p,[2,3,4])
%evaluate the polynomial at the points in the list [2,3,4].
%This gives the 3 numbers [6, 2, 0] as answers.
q=2*p
%this creates the polynomial q which is 2 multiplied by p.
%So q is the polynomial 2x**2 -18x +40
r=q+p
%this adds the two polynomials q and p
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%in what follows, we find the LAGRANGE interpolating polynomial
%for the points (1,2), (2,4) and (3,8) [these correspond to points
%on the curve of y=2**x]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
L0=poly([2,3])
L0=2*L0/[(1-2)*(1-3)]
L1=poly([1,3])
L1=4*L1/[(2-1)*(2-3)]
L2=poly([1,2])
L2=8*L2/[(3-1)*(3-2)]
L=L0+L1+L2
%this finally is the full Lagrange polynomial. Lets draw it!
x=linspace(0,4,100)
%we will plot 100 points between 0 and 4
plot(x,polyval(L,x))
%polyval(L,x) is the Lagrange polynomial evaluated at all the points
%in the list x - it gives a list of the corresponding y values.
%finally - lets draw the graph of y=2**x together with the 
%Lagrange polynomial:
plot(x,2.^x,'r:',x,polyval(L,x),'b--')
%In the above: r stands for "red", b stands for "blue",
%the : means draw a dotted line, etc.

