Shared4.1 | Class ID 23206 | 842740.ipynbOpen in CoCalc
var('x,y')
f(x,y) = e^(-x^2 * y)
show(f)
df_dx = f.diff()[0]
show(df_dx)
df_dy = f.diff()[1]
show(df_dy)

show(f.diff(2))
show(f.diff(2)[1,0])

$\left( x, y \right) \ {\mapsto} \ e^{\left(-x^{2} y\right)}$
$\left( x, y \right) \ {\mapsto} \ -2 \, x y e^{\left(-x^{2} y\right)}$
$\left( x, y \right) \ {\mapsto} \ -x^{2} e^{\left(-x^{2} y\right)}$
$\left(\begin{array}{rr} \left( x, y \right) \ {\mapsto} \ 4 \, x^{2} y^{2} e^{\left(-x^{2} y\right)} - 2 \, y e^{\left(-x^{2} y\right)} & \left( x, y \right) \ {\mapsto} \ 2 \, x^{3} y e^{\left(-x^{2} y\right)} - 2 \, x e^{\left(-x^{2} y\right)} \\ \left( x, y \right) \ {\mapsto} \ 2 \, x^{3} y e^{\left(-x^{2} y\right)} - 2 \, x e^{\left(-x^{2} y\right)} & \left( x, y \right) \ {\mapsto} \ x^{4} e^{\left(-x^{2} y\right)} \end{array}\right)$
$\left( x, y \right) \ {\mapsto} \ 2 \, x^{3} y e^{\left(-x^{2} y\right)} - 2 \, x e^{\left(-x^{2} y\right)}$
z0 = f(0,0)
print 'Z0:', z0
x_slope = df_dx(0,0)
y_slope = df_dy(0,0)
print x_slope, y_slope
x0 = 0
y0=0
Z(x,y) = z0 + x_slope*(x - x0) + y_slope*(y-y0)
show(Z)

f_plot = plot3d(f, (x, -1, 1), (y, -1, 1), color='red')
t_plot = plot3d(Z, (x, -1, 1), (y, -1, 1), color='blue')
f_plot + t_plot


Z0: 1 0 0
$\left( x, y \right) \ {\mapsto} \ 1$
#A -e
z0 = f(1,1)
print 'Z0:', z0
x_slope = df_dx(1,1)
y_slope = df_dy(1,1)
print x_slope, y_slope
x0 = 1
y0=1
Z(x,y) = z0 + x_slope*(x - x0) + y_slope*(y-y0)
show(Z)

f_plot = plot3d(f, (x, 0, 2), (y, 0, 2), color='red')
t_plot = plot3d(Z, (x, 0, 2), (y, 0, 2))
f_plot + t_plot

Z0: e^(-1) -2*e^(-1) -e^(-1)
$\left( x, y \right) \ {\mapsto} \ -2 \, {\left(x - 1\right)} e^{\left(-1\right)} - {\left(y - 1\right)} e^{\left(-1\right)} + e^{\left(-1\right)}$

# Q2¶

#a
var('x,y')
f(x, y) = 4
plot3d(f, (x, -2, 2), (y, -2, 2))

f(x,y) = x^2 + y^2

z0 = f(0,0)
print 'Z0:', z0
x_slope = f.diff()[0](0,0)
y_slope = f.diff()[1](0,0)
print x_slope, y_slope
x0 = 1
y0=1
Z(x,y) = z0 + x_slope*(x - x0) + y_slope*(y-y0)
show(Z)

f_plot = plot3d(f, (x, -1, 1), (y, -1, 1), color='red')
t_plot = plot3d(Z, (x, -1, 1), (y, -1, 1))
f_plot + t_plot

Z0: 0 0 0
$\left( x, y \right) \ {\mapsto} \ 0$
var('y')
f(x,y) = x^3 * y - x^2
plot_f = plot3d(f, (x, -1, 1), (y, -1 , 1))
plot_f