> #sfb Feb 7, 2002 > with(plots); > # Maple 2, what is the difference? > p1:=plot3d(x*y,x=-3..3,y=-3..3,style=WIREFRAME,color=red,axes=BOXED): > p2:=implicitplot3d(x*y-z,x=-3..3,y=-3..3,z=-3..3,style=WIREFRAME,color=black): > display(p1,p2); > # > ?gradplot > f:=x^2+y^2; # Valley/Local Min. grad f points outward > vec:=gradplot(f,x=-3..3,y=-3..3):vec; > con:=contourplot(f,x=-3..3,y=-3..3):con; > display(vec,con,title="Something is not right (angled)"); > display(vec,con,scaling=constrained,title="Aha, that's better"); > f:=2*x+y; # Plane/Usual view. grad f and contours perpendicular lines. > fstring:=convert(f,string): > banner:="The Good Doctor's "||fstring: #doesn't work in Maple5 > vec:=gradplot(f,x=-3..3,y=-3..3): > con:=contourplot(f,x=-3..3,y=-3..3): > display(vec,con,scaling=constrained,title=banner); > # > f:=-2*x-y; # Plane/Usual view. grad f and contours perpendicular lines. > fstring:=convert(f,string): > banner:="The Good Doctor's "||fstring: #doesn't work in Maple5 > vec:=gradplot(f,x=-3..3,y=-3..3): > con:=contourplot(f,x=-3..3,y=-3..3): > display(vec,con,scaling=constrained,title=banner); > f:=x^2-y^2; # Saddle point. grad f `flows around' > fstring:=convert(f,string): > banner:="The Good Doctor's "||fstring: > vec:=gradplot(f,x=-3..3,y=-3..3): > con:=contourplot(f,x=-3..3,y=-3..3): > display(vec,con,scaling=constrained,title=banner); > f:=-x^2-y^2; # Hill Top/Local Max. grad f points inward > fstring:=convert(f,string): > banner:="The Good Doctor's "||fstring: > vec:=gradplot(f,x=-3..3,y=-3..3): > con:=contourplot(f,x=-3..3,y=-3..3): > display(vec,con,scaling=constrained,title=banner); > f:=1-x^2-y^2+x^2*y^2; # Local Max surrounded by saddles > L:=1.5; > fstring:=convert(f,string): > banner:="The Good Doctor's "||fstring: > vec:=gradplot(f,x=-L..L,y=-L..L): > con:=contourplot(f,x=-L..L,y=-L..L): > display(vec,con,scaling=constrained,title=banner); > f:=sin(x)*sin(y); # 2 Local Max, 2 Local Min, Many Saddles > L:=Pi; > fstring:=convert(f,string): > banner:="The Good Doctor's "||fstring: > vec:=gradplot(f,x=-L..L,y=-L..L): > con:=contourplot(f,x=-L..L,y=-L..L): > display(vec,con,scaling=constrained,title=banner); > f:=x^2+y^2+z^2; #3D versions are not so illuminating > L:=3; > fstring:=convert(f,string): > banner:="The Good Doctor's "||fstring: > vec:=gradplot3d(f,x=-L..L,y=-L..L,z=-L..L): > con:=implicitplot3d(f=4,x=-L..L,y=-L..L,z=-L..L,numpoints=3000,style=PATCHNOGRID): > con2:=implicitplot3d(f=9,x=-L..L,y=-L..L,z=-L..L,style=WIREFRAME,color=red): > display(vec,con,con2,scaling=constrained,title=banner); > # > # > # Directional Derivatives (algebra) > f; > diff(f,x);diff(f,x,x);grad(f,[x,y,z]); > with(linalg):grad(f,[x,y,z]); > u:=vector([3/5,4/5,0]);fu:=dotprod(u,grad(f,[x,y,z]),orthogonal); > # Directional Derivatives (picture/graph) > with(plottools): > # > # > # Expressions and Subs, Evals > f:=cos(sqrt(x^2+y^2)/2);subs({x=1,y=2},f);subs({x=1/2},f);subs({y=2/5},f); > a:=1;b:=2;c:=eval(f,{x=a,y=b}); > fxfixed:=subs({x=a},f): > fyfixed:=subs({y=b},f): > surface:=plot3d(f,x=-1..4,y=-1..4,axes=boxed,style=PATCHNOGRID): > xsection:=spacecurve([x,b,fyfixed],x=-1..4,color=red): > ysection:=spacecurve([a,y,fxfixed],y=-1..4,color=green): > display(surface,xsection,ysection); > #arrow([a,b,c],vector([deltaA,deltaB,deltaC],...) goes from [a,b,c] to [a+deltaA,b+deltaB,c+deltaC] > # > xarrow:=arrow([a,b,0],vector([1,0,0]),.2,.6,.2,color=red): > yarrow:=arrow([a,b,0],vector([0,1,0]),.2,.6,.2,color=green): > fxvalue:=eval(diff(f,x),{x=a,y=b}); > fxarrow:=arrow([a,b,c],vector([1,0,fxvalue]),.2,.6,.2,color=red): > fyvalue:=eval(diff(f,y),{x=a,y=b}); > fyarrow:=arrow([a,b,c],vector([0,1,fyvalue]),.2,.6,.2,color=green): > display(surface,xsection,ysection,xarrow,yarrow,fxarrow,fyarrow); > normalarrow:=arrow([a,b,c],vector([-fxvalue,-fyvalue,1]),.2,.6,.2,color=blue): > theta:=40*Pi/180;ux:=cos(theta);uy:=sin(theta); > fu:=subs({x=a+ux*t,y=b+uy*t},f); > usection:=spacecurve([a+ux*t,b+uy*t,fu],t=-3..3,color=blue,thickness=3): > display(surface,xsection,ysection,usection,title="Three Cross Sections"); > uarrow:=arrow([a,b,0],vector([ux,uy,0]),.2,.6,.2,color=blue): > fuarrow:=arrow([a,b,c],vector([ux,uy,ux*fxvalue+uy*fyvalue]),.2,.6,.2,color=blue): > fuAtab:=eval( dotprod(vector([ux,uy]),grad(f,[x,y])),{x=a,y=b}); > display(surface,xsection,ysection,usection,xarrow,yarrow,uarrow,fxarrow,fyarrow,fuarrow,title="Directional Arrows"); > # tangent plane > surf2:=plot3d(f,x=-1..4,y=-1..4,contours=[0,c],axes=boxed,style=PATCHCONTOUR): > g:=c+fxvalue*(x-a)+fyvalue*(y-b); > surf3:=plot3d(g,x=-1..4,y=-1..4,contours=[0,c],axes=boxed,style=PATCHCONTOUR): > display(surf2,surf3,normalarrow,fxarrow,fyarrow,fuarrow,title="Tangent Plane"); > surf5:=plot3d(f,x=-1..4,y=-1..4,contours=[-2*c,-3*c/2,-c,-c/2,0,c/2,c,3*c/2,2*c],axes=boxed,style=PATCHCONTOUR): > surf4:=plot3d(g,x=-1..4,y=-1..4,contours=[-2*c,-3*c/2,-c,-c/2,0,c/2,c,3*c/2,2*c],axes=boxed,style=CONTOUR,color=black,thickness=3): > display(surf5,surf4,normalarrow,fxarrow,fyarrow,fuarrow,title="Tangent Plane"); > >