%matplotlib inline
from sympy import *
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation, rc
from IPython.display import HTML
# solve for h using the
h = symbols('h')
u0 = Matrix([[1],[0],[0],[0]])
u1 = Matrix([[0],[1],[0],[0]])
u2 = Matrix([[0],[0],[1],[0]])
u3 = Matrix([[0],[0],[0],[1]])
A = Matrix([[1, 0, 0, 0], [0, 1, 0, 0], [1, h, h**2, h**3], [0, 1, 2*h, 3*h**2]])
a0 = A.inv()*u0
a1 = A.inv()*u1
a2 = A.inv()*u2
a3 = A.inv()*u3
A.inv()
# make lines using h = 3
t0 = a0.subs(h,3)
t1 = a1.subs(h,3)
t2 = a2.subs(h,3)
t3 = a3.subs(h,3)
xs = np.arange(0.,606,)/100
u0 = t0[0]+(t0[1]*xs)+(t0[2]*xs**2)+(t0[3]*xs**3)
u1 = t1[0]+(t1[1]*xs)+(t1[2]*xs**2)+(t1[3]*xs**3)
u2 = t2[0]+(t2[1]*xs)+(t2[2]*xs**2)+(t2[3]*xs**3)
u3 = t3[0]+(t3[1]*xs)+(t3[2]*xs**2)+(t3[3]*xs**3)
fig, ((ax1, ax2)) = plt.subplots(nrows=1, ncols=2,)
ax1.set_ylim(-3, 3)
ax1.set_xlim(0, 3)
ax2.set_ylim(-3, 3)
ax2.set_xlim(0, 6)
ax1.set_title("Hermite basis functions")
ax1.plot(xs,u0,color = 'red')
ax1.plot(xs,u1,color = 'orange')
ax1.plot(xs,u2,color = 'blue')
ax1.plot(xs,u3,color = 'black')
ax2.set_title("expanded x axis")
ax2.plot(xs,u0,color = 'red')
ax2.plot(xs,u1,color = 'orange')
ax2.plot(xs,u2,color = 'blue')
ax2.plot(xs,u3,color = 'black')
plt.show
# get the equations for each basis function with our newly found coefficients
x = symbols('x')
ex0 = t0[0]+(t0[1]*x)+(t0[2]*x**2)+(t0[3]*x**3)
ex1 = t1[0]+(t1[1]*x)+(t1[2]*x**2)+(t1[3]*x**3)
ex2 = t2[0]+(t2[1]*x)+(t2[2]*x**2)+(t2[3]*x**3)
ex3 = t3[0]+(t3[1]*x)+(t3[2]*x**2)+(t3[3]*x**3)