#!/usr/bin/env python

import numpy as np
def f(x):
    #return x**3
    return 3*x**3 -4*x**2 + 2*x +1
def fprime(x):
    #return 3*x**2
    return 9*x**2 -8*x + 2
# TODO: also try a non-polynomial function, e.g. sin

A = np.linspace(0, 20, 20)
Y = f(A)
dY = fprime(A)

import professor2 as prof
X = np.array([[a] for a in A])
ipol = prof.Ipol(X, Y, 3, "order3")
Z  = [ipol.val(x) for x in X]
dZ = [ipol.der(x) for x in X]

#from IPython import embed
#embed()

import pylab
pylab.plot(A, Y, "ro", label="Anchors")
pylab.plot(X, Z, "-", label="Ipol")
pylab.plot(X, dZ, ":", label="Professor derivative")
pylab.plot(A, dY, "bx", label="Exact derivative")
pylab.legend(loc=2)
pylab.show()
