var('xx yy x y')
@interact
def _(F=cos(x)*cos(y),x0=(0,1.5), y0=(0, 1.5),
order=[1..10]):
plotF = plot3d(F, (-2, 2), (-2, 2), adaptive=True, color='blue')
F0 = float(F.subs(x=x0).subs(y=y0))
P = (x0, y0, F0)
dot = point3d(P, size=15, color='yellow')
plot = dot + plotF
approx = F0
for n in range(1, order+1):
for i in range(n+1):
if i == 0:
deriv = F.diff(y, n)
elif i == n:
deriv = F.diff(x, n)
else:
deriv = F.diff(x, i).diff(y, n-i)
deriv = float(deriv.subs(x=x0).subs(y=y0))
coeff = binomial(n, i)/factorial(n)
approx += coeff * deriv * (x-x0)^i * (y-y0)^(n-i)
plot += plot3d(approx, (x, -2, 2),
(y, -2, 2), color='red', opacity=0.7)
pretty_print("F(x,y) =",F)
show(plot)