222 - Topic 06 - Directional Derivatives

2495 days ago by Professor222

John Travis

Mississippi College

This worksheet derived from a worksheet posted at http://wiki.sagemath.org/interact/calculus

%auto var('x,y,t,z') # f(x,y)=y*cos(x-y) pif = float(pi) # use this if you would rather have decimal angles line_thickness=3 surface_color='blue' plane_color='yellow' line_color='red' tangent_color='green' gradient_color='orange' @interact def myfun(f=input_box(y*cos(x-y)),location=input_grid(1, 2, default=[1,2], label = "Location (x,y)", width=2), angle=slider(0, 2*pi, pi/90, 0, label = "Angle"), show_surface=("Show surface", False)): location3d = vector(location[0]+[0]) location = location3d[0:2] direction3d = vector(RDF, [cos(angle), sin(angle), 0]) direction=direction3d[0:2] cos_angle = math.cos(angle) sin_angle = math.sin(angle) df = f.gradient() direction_vector=line3d([location3d, location3d+direction3d], arrow_head=True, rgbcolor=line_color, thickness=line_thickness) curve_point = (location+t*direction).list() curve = parametric_plot(curve_point+[f(x=curve_point[0],y=curve_point[1])], (t,-3,3),color=line_color,thickness=line_thickness) plane = parametric_plot((cos_angle*x+location[0],sin_angle*x+location[1],t), (x, -3,3), (t,-3,3),opacity=0.8, color=plane_color) pt = point3d(location3d.list(),color='green', size=10) tangent_line = parametric_plot((location[0]+t*cos_angle, location[1]+t*sin_angle, f(x=location[0],y=location[1])+t*df(x=location[0],y=location[1])*(direction)), (t, -3,3), thickness=line_thickness, color=tangent_color) picture3d = direction_vector+curve+plane+pt+tangent_line picture2d = contour_plot(f, (x,-3,3),(y,-3,3), plot_points=200,contours=200,cmap='Accent_r',colorbar=1)+point2d(location,size=25,zorder=3) picture2d += arrow(location.list(), (location+direction).list()) picture2d += point(location.list(),rgbcolor='green',pointsize=40) dff = df(x=location[0], y=location[1]) picture2d += arrow(location.list(), (location+dff).list(), rgbcolor=gradient_color, width=line_thickness) show(picture2d, aspect_ratio=1) if show_surface: picture3d += plot3d(f, (x,-3,3),(y,-3,3),opacity=0.7) dff3d = vector(RDF,dff.list()+[0]) picture3d += line3d([location3d, location3d+dff3d], arrow_head=True, rgbcolor=gradient_color, thickness=line_thickness) show(picture3d,aspect=[1,1,1], axes=True) 
       
Location (x,y) 
Angle 
Show surface 

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