from __future__ import division
import numpy as np
import numpy.linalg as la
import matplotlib.pyplot as pt
#nodes = [0, 0.3]
nodes = [0, 0.3, 0.8]
#nodes = [0, 0.3, 0.8, 2, 3]
def lagrange_basis_func(j, x):
...
return result
(Edit cell for solution)
mesh = np.linspace(-0.5, 3.5, 100)
pt.axhline(0, color="black")
pt.axhline(1, linestyle="--", color="black", alpha=0.3)
for node in nodes:
pt.axvline(node, linestyle="--", color="black", alpha=0.3)
for i in range(len(nodes)):
pt.plot(mesh, lagrange_basis_func(i, mesh))
pt.ylim([-2,2])
Questions:
nodes = [0, 0.5, 2, 2.5]
values = np.random.randn(4)
def f(x):
# Make f interpolate 'values' at 'nodes'
return (
...
)
(Edit this cell for solution.)
pt.plot(nodes, values, "o")
pt.plot(mesh, f(mesh))