Directional Derivatives

## Description

This interact illustrates the concept of a directional derivative by plotting the tangent line at \$(x, y)\$ on the trace of the given surface on the plane orthogonal to the xy plane and containing the red vector. (The orange vector is the gradient) The user may change the point \$(x, y)\$ at which they wish to view the directional derivative and the angle between the gradient and the red (direction) vector. The interact also provides a contour plot to view the gradient and direction vector.

## Sage Cell

#### Code

``````var('x,y,t,z')
f(x,y)=sin(x)*cos(y)

pif = float(pi)

line_thickness=3
surface_color='blue'
plane_color='purple'
line_color='red'
tangent_color='green'

@interact
def myfun(location=input_grid(1, 2, default=[0,0], label = "Location (x,y)", width=2), angle=slider(0, 2*pif, label = "Angle"),
show_surface=("Show surface", True)):
location3d = vector(location+)
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)
curve_point = (location+t*direction).list()
curve = parametric_plot(curve_point+[f(*curve_point)], (t,-3,3),color=line_color,thickness=line_thickness)
plane = parametric_plot((cos_angle*x+location,sin_angle*x+location,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+t*cos_angle, location+t*sin_angle, f(*location)+t*df(*location)*(direction)), (t, -3,3), thickness=line_thickness, color=tangent_color)
picture3d = direction_vector+curve+plane+pt+tangent_line

picture2d = contour_plot(f(x,y), (x,-3,3),(y,-3,3), plot_points=100)
picture2d += arrow(location.list(), (location+direction).list())
picture2d += point(location.list(),rgbcolor='green',pointsize=40)
if show_surface:
picture3d += plot3d(f, (x,-3,3),(y,-3,3),opacity=0.7)

dff = df(location, location)
dff3d = vector(RDF,dff.list()+)
picture2d += arrow(location.list(), (location+dff).list(), rgbcolor=gradient_color, width=line_thickness)
show(picture3d,aspect=[1,1,1], axes=True)
show(picture2d, aspect_ratio=1)```
```

none

## Tags

Primary Tags:

Secondary Tags:

A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.

## Related Cells

Any related cells go here. Provide a link to the page containing the information about the cell.