%auto
## An interactive way to demonstrate limits of multivariate functions of the form z = f(x,y)
##
## John Travis
## Mississippi College
##
## Spring 2011
##
# Starting point for radius values before collapsing in as R approaches 0.
# Functions ought to be "reasonable" within a circular domain of radius R surrounding
# the desired (x_0,y_0).
var('x,y,z')
Rmin=1/10
Rmax=2
f1 = sin(x^2+y^2-1)/(1-x^2-y^2)
f2 = sin(x*y)
f3 = ln(abs(x-y))
f4 = (x^3-y^3)/(x^2+y^2)
f5 = x^3*y/(x^6+y^2)
f6 = x^2*y^2/(5*x^4+y^4)
@interact(layout=dict(top=[['f'],['x0'],['y0']],
bottom=[['in_3d','curves','R']]))
def _(f=selector([f1,f2,f3,f4,f5,f6],buttons=False,label='f(x,y)='),
R=slider(Rmin,Rmax,1/10,Rmax,label=', $R$'),
x0=input_box(0,width=10,label='$x_0$'),
y0=input_box(0,width=10,label='$y_0$'),
curves=checkbox(default=false,label='Show curves'),
in_3d=checkbox(default=false,label='3D')):
# converting f to cylindrical coordinates.
g(r,t) = f(x=r*cos(t)+x0,y=r*sin(t)+y0)
# Sage graphing transformation used to see the original surface.
cylinder = (r*cos(t)+x0,r*sin(t)+y0,z)
surface = plot3d(g,(t,0,2*pi),(r,1/100,Rmax),transformation=cylinder,opacity=0.2)
# Regraph the surface for smaller and smaller radii controlled by the slider.
collapsing_surface = plot3d(g,(t,0,2*pi),(r,1/100,R),transformation=cylinder,rgbcolor=(0,1,0))
G = surface+collapsing_surface
pretty_print(html('Enter $(x_0 ,y_0 )$ above and see what happens as $ R \\rightarrow 0 $.'))
pretty_print(html('The surface has a limit as $(x,y) \\rightarrow $ ('+str(x0)+','+str(y0)+') if the green region collapses to a point.'))
# If checked, add a couple of curves on the surface corresponding to limit as x->x0 for y=x^(3/5),
# and as y->y0 for x=y^(3/5). Should make this more robust but perhaps using
# these relatively obtuse curves could eliminate problems.
H = contour_plot(f,(x,x0-1,x0+1),(y,y0-1,y0+1),cmap=True,fill=False,contours=100)
if curves:
curve_x = parametric_plot3d([x0-t,y0-t^(3/5),f(x=x0-t,y=y0-t^(3/5))],(t,Rmin,Rmax),color='red',thickness=10)
curve_y = parametric_plot3d([x0+t^(3/5),y0+t,f(x=x0+t^(3/5),y=y0+t)],(t,Rmin,Rmax),color='red',thickness=10)
curve_xnoz = parametric_plot([x0-t,y0-t^(3/5)],(t,0.01,Rmax/2),color='black',thickness=2)
curve_ynoz = parametric_plot([x0+t^(3/5),y0+t],(t,0.01,Rmax/2),color='black',thickness=2)
R2 = Rmin/4
G += arrow((x0-Rmin,y0-Rmin^(3/5),f(x=x0-Rmin,y=y0-Rmin^(3/5))),(x0-R2,y0-R2^(3/5),f(x=x0-R2,y=y0-R2^(3/5))),size=30 )
G += arrow((x0+Rmin^(3/5),y0+Rmin,f(x=x0+Rmin^(3/5),y=y0+Rmin)),(x0+R2^(3/5),y0+R2,f(x=x0+R2^(3/5),y=y0+R2)),size=30 )
limit_x = limit(f(x=x0-t,y=y0-t^(3/5)),t=0)
limit_y = limit(f(x=x0+t^(3/5),y=y0+t),t=0)
text_x = text3d(limit_x,(x0,y0,limit_x))
text_y = text3d(limit_y,(x0,y0,limit_y))
G += curve_x+curve_y+text_x+text_y
H += curve_xnoz+curve_ynoz
pretty_print(html('The red curves represent a couple of trajectories on the surface. If they do not meet, then'))
pretty_print(html('there is also no limit. (If computer hangs up, likely the computer can not do these limits.)'))
pretty_print(html('\n<center><font color="red">$\lim_{(x,?)\\rightarrow(x_0,y_0)} f(x,y) =%s$</font>'%str(limit_x)+' and <font color="red">$\lim_{(?,y)\\rightarrow(x_0,y_0)} f(x,y) =%s$</font></center>'%str(limit_y)))
pretty_print(html('\n For this problem, the surface is $z = %s$'%str(latex(f))))
if in_3d:
show(G,stereo="redcyan")
else:
show(G,perspective_depth=true)
H.show(figsize=(4,6))
|
Click to the left again to hide and once more to show the dynamic interactive window
|