# MAT 223 Partial Derivatives and More

## 970 days ago by kcrisman

Here is what a partial derivative is, from three perspectives.

var('y,z') @interact def _(my_point = matrix([[2,1]]), f = 1/4*x^2-1/8*y^2,show_plane=True,deriv=['x','y']): a,b = my_point[0,0],my_point[0,1] f(x,y) = f P = plot3d(f,(x,a-2,a+2),(y,b-2,b+2)) P += point3d((a,b,f(a,b)),color='green',size=20) if deriv == 'y': P += parametric_plot3d((a,y,f(a,y)),(y,b-2,b+2),color='red',thickness=10) if show_plane: P += implicit_plot3d(x==a,(x,a-2,a+2),(y,b-2,b+2),(z,f(a,b)-2,f(a,b)+2),color='red') if deriv == 'x': P += parametric_plot3d((x,b,f(x,b)),(x,a-2,a+2),color='red',thickness=10) if show_plane: P += implicit_plot3d(y==b,(x,a-2,a+2),(y,b-2,b+2),(z,f(a,b)-2,f(a,b)+2),color='red') P.show(aspect_ratio=1) if deriv == 'y': Q = plot(f(a,y),(y,b-2,b+2)) Q += point((b,f(a,b)),color='green',size=20) if deriv == 'x': Q = plot(f(x,b),(x,a-2,a+2)) Q += point((a,f(a,b)),color='green',size=20) R = contour_plot(f,(x,a-2,a+2),(y,b-2,b+2)) if deriv == 'y': R += line([(a,b-2),(a,b+2)],color='red') if deriv == 'x': R += line([(a-2,b),(a+2,b)],color='red') R += point((a,b),color='green',size=20,zorder=4) graphics_array([Q,R]).show(figsize=[6,3])

## Click to the left again to hide and once more to show the dynamic interactive window

var('y') @interact def _(f = x*y*(x^2-y^2)/(x^2+y^2),deriv=['x','y']): my_point = matrix([[0,0]]) a,b = my_point[0,0],my_point[0,1] f(x,y) = f P = plot3d(f,(x,a-2,a+2),(y,b-2,b+2)) P += point3d((0,0,0),color='green',size=20) if deriv == 'y': P += parametric_plot3d((a,y,f(a,y)),(y,b-2,b+2),color='red',thickness=10) if deriv == 'x': P += parametric_plot3d((x,b,f(x,b)),(x,a-2,a+2),color='red',thickness=10) P.show(aspect_ratio=1)

## Click to the left again to hide and once more to show the dynamic interactive window

Here is the function again.  But note that the only place the mixed partials aren't equal is at zero, which we can't see.

var('x,y') f = x*y*(x^2-y^2)/(x^2+y^2) show(plot3d(diff(f,y),(x,-1,1),(y,-1,1)),plot_points=200) show(plot3d(diff(f,x),(x,-1,1),(y,-1,1)),plot_points=200) show(plot3d(diff(f,y,x),(x,-1,1),(y,-1,1)),plot_points=200) show(plot3d(diff(f,x,y),(x,-1,1),(y,-1,1)),plot_points=200)

Recall the notion of local linear approximations from Calculus I:

@interact def _(eps=1): show(plot(x^(1/3),(x,8-eps,8+eps),legend_label='$\\sqrt[3]{x}$')+plot((1/12)*(x-8)+2,(x,8-eps,8+eps),color='green',legend_label='$L(x)$'))

## Click to the left again to hide and once more to show the dynamic interactive window

And don't forget, you can't have a local linear approximation without a derivative!

@interact def _(eps=1): show(plot(abs(4-x^2),(x,2-eps,2+eps)))

## Click to the left again to hide and once more to show the dynamic interactive window

Okay, so what does this look like for a surface or for a function of two variables?  Answer - we get tangent planes.

var('y,z') @interact def _(my_point = matrix(RR,[[2,1]]), eps=2, f = 1/4*x^2+1/8*y^2,show_plane=True,show_vectors=False,show_normal=False): a,b = my_point[0,0],my_point[0,1] f(x,y) = f P = plot3d(f,(x,a-eps,a+eps),(y,b-eps,b+eps)) P += point3d((a,b,f(a,b)),color='green',size=20) fx = f.diff(x) fy = f.diff(y) if show_plane: P += plot3d(f(a,b)+fx(a,b)*(x-a)+fy(a,b)*(y-b),(x,a-eps,a+eps),(y,b-eps,b+eps),color='red') if show_vectors: P += arrow3d((a,b,f(a,b)),(a+1,b,f(a,b)+fx(a,b)),color='purple',width=2) P += arrow3d((a,b,f(a,b)),(a,b+1,f(a,b)+fy(a,b)),color='purple',width=2) if show_normal: P += arrow3d((a,b,f(a,b)),(a-fx(a,b),b-fy(a,b),f(a,b)+1),color='purple',width=2) P.show(aspect_ratio=1)

## Click to the left again to hide and once more to show the dynamic interactive window

var('y z') @interact def _(function=x^2+y^2-25*x*y,xbounds=matrix([[-3.5,3.5]]),ybounds=matrix([[-3.5,3.5]]),point=matrix([[1,2]]),auto_update=False,fill=False,contours=10): C = contour_plot(function,(x,xbounds[0][0],xbounds[0][1]),(y,ybounds[0][0],ybounds[0][1]),labels=True,fill=fill,contours=contours) F(x,y) = function G = diff(F) V = plot_vector_field((G[0],G[1]),(x,xbounds[0][0],xbounds[0][1]),(y,ybounds[0][0],ybounds[0][1])) a,b = point[0][0],point[0][1] P = point2d((a,b),size=20) show(P+V+C,aspect_ratio=1)

function
xbounds
ybounds
point
fill
contours

## Click to the left again to hide and once more to show the dynamic interactive window

var('y z') @interact def _(function=x^2+y^2-25*x*y+z,xbounds=matrix([[-3.5,3.5]]),ybounds=matrix([[-3.5,3.5]]),zbounds=matrix([[-3.5,3.5]]),point=matrix([[1,2,3]]),auto_update=False,fill=False): F(x,y,z) = function G = diff(F) V = plot_vector_field3d((G[0],G[1],G[2]),(x,xbounds[0][0],xbounds[0][1]),(y,ybounds[0][0],ybounds[0][1]),(z,zbounds[0][0],zbounds[0][1])) a,b,c = point[0][0],point[0][1],point[0][2] P = point3d((a,b,c),size=20) show(P+V,aspect_ratio=1)

## Click to the left again to hide and once more to show the dynamic interactive window

var('y z') @interact def _(function=e^(4*x^2-y),xbounds=matrix([[-2.5,2.5]]),ybounds=matrix([[-2.5,2.5]]),point=matrix([[1,4]]),auto_update=False,fill=False,arr=(None,['arrow1','arrow2','none'])): a,b = point[0][0],point[0][1] C = contour_plot(function,(x,xbounds[0][0]+a,a+xbounds[0][1]),(y,ybounds[0][0]+b,b+ybounds[0][1]),labels=True,fill=fill,contours=[10^j for j in [-10..20]]) F(x,y) = function G = diff(F) P = point2d((a,b),size=20) if arr=='arrow1': V = arrow([a,b],[a-2,b-1]) if arr=='arrow2': V = arrow([a,b],[a+8,b+4]) else: V = Graphics() show(P+C+V,aspect_ratio=1)

## Click to the left again to hide and once more to show the dynamic interactive window

var('y z') @interact def _(function=x^2+y^2,xbounds=matrix([[-3.5,3.5]]),ybounds=matrix([[-3.5,3.5]]),zbounds=matrix([[-3.5,3.5]]),point=matrix([[-1,2,1]]),auto_update=False,shells=False,plane=False): F(x,y,z) = x^2+y^2+z^2 Z = implicit_plot3d(F==6,(x,xbounds[0][0],xbounds[0][1]),(y,ybounds[0][0],ybounds[0][1]),(z,zbounds[0][0],zbounds[0][1]),color='red',opacity=.3) G = diff(F) a,b,c = point[0][0],point[0][1],point[0][2] P = point3d((a,b,c),size=20)+Z P += arrow([-1,2,1],[-2-1,4+2,2+1]) if shells: P += sum([implicit_plot3d(F==c,(x,xbounds[0][0],xbounds[0][1]),(y,ybounds[0][0],ybounds[0][1]),(z,zbounds[0][0],zbounds[0][1]),color='red',opacity=.1) for c in [2,4,8,10]]) if plane: P += plot3d(6+x-2*y,(x,xbounds[0][0],xbounds[0][1]),(y,ybounds[0][0],ybounds[0][1])) show(P,aspect_ratio=1)

## Click to the left again to hide and once more to show the dynamic interactive window

var('y z') @interact def _(function=sin(x)+cos(y),xbounds=matrix([[-3.5,3.5]]),ybounds=matrix([[-3.5,3.5]]),point=matrix([[0,-2]]),auto_update=False): C = plot3d(function,(x,xbounds[0][0],xbounds[0][1]),(y,ybounds[0][0],ybounds[0][1])) F(x,y) = function a,b = point[0][0],point[0][1] G = F.gradient()(x=a,y=b) V = arrow([a,b,F(a,b)],[G[0]+a,G[1]+b,norm(G)+F(a,b)],width=5,color='red') P = point3d((a,b,F(a,b)),size=20,color='red') show(P+V+C,aspect_ratio=1)

function
xbounds
ybounds
point

## Click to the left again to hide and once more to show the dynamic interactive window

var('y') P = plot3d(2*x*y/(x^2+y^2),(x,-1,1),(y,-1,1),plot_points=250) Q = parametric_plot3d((x,0,0),(x,-1,1),color='red',thickness=5) R = parametric_plot3d((x,x,1),(x,-1,1),color='green',thickness=5) R2 = parametric_plot3d((x,-x,-1),(x,-1,1),color='green',thickness=5) R3 = parametric_plot3d((x,2*x,4/5),(x,-1,1),color='green',thickness=5) S = parametric_plot3d((0,y,0),(y,-1,1),color='purple',thickness=5) (P+Q+R+R2+R3+S).show(aspect_ratio=1)