Pseudo code below: # Constructing the polynomial x^2 + y^2 x = np.linspace(-1, 1, 10) y
Question:
Pseudo code below:
# Constructing the polynomial x^2 + y^2
x = np.linspace(-1, 1, 10)
y = np.linspace(-1, 1, 10)
x, y = np.meshgrid(x, y, copy=False)
Z = x**2 + y**2 + np.random.rand(*x.shape)*0.01
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(x, y, Z, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
plt.title('Original Surface')
X = x.flatten()
Y = y.flatten()
# Create the matrix A
A = #TODO
b = #TODO
# Solve for theta
Q = #TODO
Q1 = #TODO
theta = #TODO
print("Estimated parameters are theta = [%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f]" %(theta[0],theta[1],theta[2],theta[3],theta[4],theta[5]))
# Compute the estimated polynomial
Zest = theta[0] + theta[1]*x + theta[2]*y + theta[3]*x**2 + theta[4]*x*y+ theta[5]*y**2
fig1 = plt.figure()
ax = fig1.gca(projection='3d')
surf = ax.plot_surface(x, y, Zest, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
c=plt.title('Estimated Surface')