CoCalc Public FilesFunction Graphs and Contour Maps.sagewsOpen in with one click!
Author: Thomas Krainer
Views : 30
Description: Worksheet to illustrate graphs and contour maps for functions of two variables
# Function Graphs and Contour Maps # Author: Thomas Krainer (Penn State Altoona) # Prior Version: 09/20/2011 # Version: 02/11/2016 # x,y=var('x,y') html('<h1>Graphs and contour maps for functions of 2 variables</h1>') html('<p>With this worksheet graphs and contour maps for functions $z = f(x,y)$ can be explored.</p>') @interact def GraphsContourMaps(function=input_box(default=sin(x)*cos(y),type=SR,label='$f(x,y)=$'),\ xinterval=input_box(default='[0,4*pi]',type=str,label='$[x_{\\min},x_{\\max}]=$'),\ yinterval=input_box(default='[0,4*pi]',type=str,label='$[y_{\\min},y_{\\max}]=$'),\ numbercontours=slider(1,30,1,default=15,label='Number of level curves:'),\ levelslider=slider(0,100,1,default=40,display_value=False,label='Level:'),\ scalingconstrained=('Do not scale plots:',False)): # Process input f(x,y)=function [xmin,xmax]=sage_eval(xinterval) [ymin,ymax]=sage_eval(yinterval) graph=plot3d(f(x,y),(x,xmin,xmax),(y,ymin,ymax),color=(135/255,180/255,250/255),plot_points=350) minlevel=graph.bounding_box()[0][2] maxlevel=graph.bounding_box()[1][2] level=minlevel+(levelslider/100)*(maxlevel-minlevel) plane=plot3d(level,(x,xmin,xmax),(y,ymin,ymax),color='green',opacity=0.8) contourmap=contour_plot(f(x,y),(x,xmin,xmax),(y,ymin,ymax),colorbar=True,\ fill=False,cmap='hsv',contours=numbercontours) levelcurve=implicit_plot(f(x,y)-level,(x,xmin,xmax),(y,ymin,ymax),linewidth=3,color='black') html('Function: $f(x,y) = %s \\; \\textrm{for} \\; (x,y) \\in [%s,%s]\\times[%s,%s]$ </br>'%(latex(f(x,y)),latex(xmin),latex(xmax),latex(ymin),latex(ymax))) html('Level Curve: $f(x,y) = %s$ </br>'%(latex(level))) if (scalingconstrained==True): show(graph+plane,aspect_ratio=1) show(contourmap+levelcurve,aspect_ratio=1) else: show(graph+plane) show(contourmap+levelcurve)

Graphs and contour maps for functions of 2 variables

With this worksheet graphs and contour maps for functions z=f(x,y)z = f(x,y) can be explored.

Interact: please open in CoCalc