# Inverse Function Maplet # Copyright 2002 Waterloo Maple Inc. # # This maplet illustrates the concept of inverse functions. # # The user enters a function and selects the 'Plot' button. Then the graph of the function and its refelction about the line y=x, which is the graph of its inverse function, are plotted. # # You can hide the graph of the function, the graph of the inverse function, or the line of reflection y=x. # # You can also change the view of the coordinate plane by setting the ranges of x and y axes. # # To run this maplet, click the !!! button in the tool bar. # restart; InverseMaplet := module() ############################################################ export getInversePlot, runInverseMaplet: local helpStr: ############################################################ ############################################################ helpStr := "This maplet illustrates the concept of inverse functions. The user enters a function and selects the 'Plot' button. Then the graph of the function and its reflection about the line y=x, which is the graph of its inverse function, are plotted. You can hide the graph of the function, the graph of the inverse function, or the line of reflection y=x. You can also change the view of the coordinate plane by setting the ranges of x and y axes.": ############################################################ ############################################################ # pre: three boolean values are input to determine the appearances # of function, line y=x and inverse function. They can't # be all zero # post: Student:-Calculus1:-InversePlot() returns getInversePlot := proc(boo1, boo2, boo3, P_origFun, P_inv_from, P_inv_to, P_invx1, P_invx2, P_invy1, P_invy2) local temp, temp2, str, viewExpr: use Maplets:-Tools in str:=StringTools:-Trim(P_origFun): if str="" then error "No function or algebraic expression input": end if: temp:=StringTools:-Trim(P_inv_from): temp2:=StringTools:-Trim(P_inv_to): if temp<>"" and temp2<>"" then str:=cat(str, ", ", temp, "..", temp2): end if: if not(boo1 or boo2 or boo3) then return plots[textplot]([1,2,"Select function, line y=x, or inverse"]): end if: if not boo1 then str := cat(str, ", showfunction=false") end if: if not boo2 then str := cat(str, ", showline=false") end if: if not boo3 then str := cat(str, ", showinverse=false") end if: viewExpr := ["DEFAULT","DEFAULT"]: temp:=P_invx1: temp:=StringTools:-Trim(temp): temp2:=P_invx2: temp2:=StringTools:-Trim(temp2): if temp<>"" and temp2<>"" then temp:=cat(temp, "..", temp2): viewExpr[1]:=temp: end if: temp:=P_invy1: temp:=StringTools:-Trim(temp): temp2:=P_invy2: temp2:=StringTools:-Trim(temp2): if temp<>"" and temp2<>"" then temp:=cat(temp, "..", temp2): viewExpr[2]:=temp: end if: temp:=cat(", view=[", viewExpr[1], ", ", viewExpr[2], "]"): str := cat(str, temp): Student:-Calculus1:-InversePlot(parse(str)): end use: end proc: ############################################################ ############################################################ # pre: null # post: run Inverse Function Maplet runInverseMaplet := proc() local maplet: use Maplets:-Elements in ############################################################ maplet := Maplet( 'onstartup'=RunWindow('mainWin'), ############################################################ Font['invFontI']('family'="Default", 'bold'='true', 'italic'='true', 'size'=12), Font['invFontB']('family'="Default", 'bold'='true', 'size'=14), ############################################################ MenuBar['MB']( Menu("File", MenuItem("Plot", 'onclick'='A_plotInverse'), MenuSeparator(), MenuItem("Close", 'onclick'=Shutdown()) ), # end Menu/File Menu("Help", MenuItem("About this maplet", 'onclick'=RunWindow('helpWin')) ) # end menu/Help ), # end MenuBar ############################################################ Window['mainWin']('resizable'='false', 'title'="Calculus 1 - Inverse Function", 'menubar'='MB', BoxColumn('inset'=0, 'spacing'=0, 'background'="#DDFFFF", BoxRow('inset'=0, 'spacing'=2, 'background'="#DDFFFF", 'border'='true', 'caption'="Enter a function and its domain", Label("Function ", 'font'='invFontB', 'background'="#DDFFFF"), TextField['origFun']('width'=16, 'background'="#EEFFFF", 'tooltip'="Enter any valid function or expression", 'value'=exp(x)), Label(" a", 'font'='invFontB', 'background'="#DDFFFF"), Label(" = ", 'font'='invFontB', 'background'="#DDFFFF"), TextField['inv_from']('value'="-2", 'width'=2, 'background'="#EEFFFF", 'tooltip'="Domain"), Label(" b", 'font'='invFontB', 'background'="#DDFFFF"), Label(" = ", 'font'='invFontB', 'background'="#DDFFFF"), TextField['inv_to']('value'="2", 'width'=2, 'background'="#EEFFFF", 'tooltip'="Domain") ), # end BoxRow BoxRow('inset'=0, 'spacing'=0, 'background'="#DDFFFF", 'border'='true', 'caption'="Plot Window", Plotter['invPlotter']('background'="#EEFFFF") ), # end BoxRow BoxRow('inset'=0, 'spacing'=0, 'background'="#DDFFFF", BoxColumn('inset'=0, 'spacing'=10, 'background'="#DDFFFF", 'border'='true', 'caption'="Display Options", BoxRow('inset'=0, 'spacing'=4, 'background'="#DDFFFF", CheckBox['TBh1']("Show function", 'value'=true, 'background'="#DDFFFF"), CheckBox['TBh2']("Show line y=x", 'value'=true, 'background'="#DDFFFF"), CheckBox['TBh3']("Show inverse", 'value'=true, 'background'="#DDFFFF") ), # end BoxRow BoxRow('inset'=0, 'spacing'=3, 'background'="#DDFFFF", Label("x =", 'font'='invFontB', 'background'="#DDFFFF"), TextField['invx1'](2, 'background'="#EEFFFF",'value'=" "), Label("..", 'font'='invFontB', 'background'="#DDFFFF"), TextField['invx2'](2, 'background'="#EEFFFF",'value'=" "), Label("y =", 'font'='invFontB', 'background'="#DDFFFF"), TextField['invy1'](2, 'background'="#EEFFFF",'value'=" "), Label("..", 'font'='invFontB', 'background'="#DDFFFF"), TextField['invy2'](2, 'background'="#EEFFFF",'value'=" ") ) # end BoxRow ), # end Column BoxRow('inset'=0, 'spacing'=10, 'background'="#DDFFFF", Button("Plot ", 'tooltip'="Plot", 'background'="#CCFFFF", 'onclick'='A_plotInverse' ), Button("Close", Shutdown(), 'background'="#CCFFFF") ) # end BoxRow ) # end BoxRow ) # end BoxColumn ), # end Window ############################################################ Window['helpWin']( 'resizable'='false', 'title'="About the Inverse Function Maplet", BoxColumn('border'='true', 'inset'=0, 'spacing'=10, 'background'="#CCFFFF", BoxCell( TextBox('height'=16, 'width'=30, 'background'="#EEFFFF", 'foreground'="#333399", 'editable'='false', 'font'='invFontB', 'value'=helpStr ) # end TextBox ), # end BoxCell BoxRow('inset'=0, 'spacing'=0, 'background'="#CCFFFF", Button("Close", CloseWindow('helpWin'), 'background'="#DDFFFF") ) # end BoxRow ) # end BoxColumn ), # end helpWin ############################################################ Action['A_plotInverse'] ( Evaluate ('waitforresult'='false', 'target'='invPlotter', 'function'='getInversePlot', Argument(TBh1), Argument(TBh2), Argument(TBh3), Argument('origFun' , quotedtext='true'), Argument('inv_from', quotedtext='true'), Argument('inv_to', quotedtext='true'), Argument('invx1', quotedtext='true'), Argument('invx2', quotedtext='true'), Argument('invy1', quotedtext='true'), Argument('invy2', quotedtext='true') ) ) ############################################################ ): # end Maplet ############################################################ Maplets:-Display(maplet): end use: # end use end proc: # end proc ############################################################ end module: # end InverseMaplet InverseMaplet:-runInverseMaplet();