import numpy as np
import numpy.linalg as la
alpha = 3
beta = 2
gamma = 2
def f(x):
return alpha*x**2 + beta*x + gamma
plot_grid = np.linspace(-3, 3, 100)
plot(plot_grid, f(plot_grid))
npts = 5
np.random.seed(22)
points = np.linspace(-2, 2, npts) + np.random.randn(npts)
values = f(points) + 0.3*np.random.randn(npts)*f(points)
plot(plot_grid, f(plot_grid))
plot(points, values, "o")
A = np.array([
np.ones(npts),
points,
points**2
]).T
print A
x = ...
x
(Edit this cell for solution.)
... = x
def f_c(x):
return alpha_c*x**2 + beta_c*x + gamma_c
plot(plot_grid, f(plot_grid), label="true")
plot(points, values, "o", label="data")
plot(plot_grid, f_c(plot_grid), label="found")
legend()
(Edit this cell for solution.)