# Calculus Exploration 7: Max Area of Box within a Parabola & Basic Curve Analysis Maplets # # The following is the Maple code for the Max Area of Box within a Parabola Maplet and the Basic Curve Analysis Maplet. Instructions for each exploration are contained in the title line of each maplet. # # Max Area of Box within a Parabola # Click in red area and press [Enter]. # Area Maximization Maplet # Copyright 2002 Waterloo Maple Inc. # # The Area Maximization maplet is designed to give the user an intuitive understanding of optimization problems. It provides an interactive demonstration of the following problem typically studied in calculus. # # Given a parabola with real roots, find the rectangle between the parabola and the x-axis that has maximal area. # # The user enters the expression for a parabola in the uppermost text area. The user experiments with the value of the width of the box by entering values in the text region to try to approach the optimum by trial and error. # # When the user clicks the Optimize button, the optimal solution is displayed both numerically and graphically. # # To run this maplet, click the Execute (!!!) button in the context bar. # restart; AreaMaximiztionMaplet:= module() ############################################################ export parabArea, parabRoots, parabInitialDraw, parabDraw,parabOptWidth,runAreaMaximization: local helpStr: ############################################################ helpStr:= "The Area Maximization maplet is designed to give you an intuitive understanding of optimization problems. It provides an interactive demonstration of the following problem typically studied in calculus. Given a parabola with real roots, find the rectangle between the parabola and the x-axis that has maximal area. Enter the expression for a parabola in the uppermost text area. Experiment with the value of the width of the box by entering values in the text region to try to approach the optimum by trial and error. To display the optimal solution both numerically and graphically, click the 'Optimize' button.": ############################################################ #computes the area of a rectangle of width width embedded between a parabola f and #the x-axis parabArea := proc(fun, width) local cent, f, wid; f:=parse(fun): f:=unapply(f,x): wid:=parse(width): if type(wid, constant) and Im(wid)=0 and evalf(wid)>=0 then cent:=solve(diff(f(x),x)=0,x); evalf(abs(wid*f(cent+wid/2.0)), 4); else error "Width must be a real, non-negative constant"; end if; end proc: ############################################################ #computes the roots of parabola f and returns them in ascending order parabRoots := proc(f) local Roots; if type(f(x),quadratic) then Roots:=solve(f(x)=0,x); if Im(Roots[1])=0 and Im(Roots[2])=0 then [min(Roots), max(Roots)]; else error "The parabola must intersect the x-axis"; end if; else error "Entered function must be quadratic"; end if; end proc: ############################################################ #draws parabola parabInitialDraw := proc(fun) local Roots ,f; f:=parse(fun): f:=unapply(f,x): Roots:=parabRoots(f); plot(f, Roots[1]-1..Roots[2]+1, thickness=3); end proc: ############################################################ #draws parabola f along with the embedded rectangle of width width parabDraw := proc(fun, wid) local cent, d, rec1, graph, Roots,width,f; f:=parse(fun): f:=unapply(f,x): width:=parse(wid): if type(width, constant) and Im(width)=0 and evalf(width)>=0 then Roots:=parabRoots(f); if evalf(width) <= evalf(abs(Roots[2]-Roots[1])) then cent := (Roots[1]+Roots[2])/2.0; d := width/2.0; rec1 := plottools[rectangle]([cent-d, 0],[cent+d, f(cent+d)], color=green, thickness=2); graph := plot(f, Roots[1]-1..Roots[2]+1, thickness=3): plots[display](rec1, graph); else error "This box does not fit between the parabola and the x-axis" end if; else error "Width must be real and non-negative"; end if; end proc: ############################################################ #computes the width of a box embedded between parabola f and the x-axis having #maximal area parabOptWidth := proc(fun) local Roots, wCrits, wOpt, areaOpt, cent,f; f:=parse(fun): f:=unapply(f,x): Roots:=parabRoots(f); cent:=solve( diff(f(x),x)=0, x); areaOpt := wOpt*f(cent+wOpt/2); wCrits := solve( diff(areaOpt,wOpt)=0, wOpt ); max(wCrits[1], wCrits[2]); end proc: ############################################################ runAreaMaximization :=proc() local maplet: use Maplets:-Elements in maplet := Maplet( 'onstartup'=RunWindow('mainWin'), Font['F2']('family'="Default", 'bold'='true', 'size'=14), MenuBar['MB']( Menu("File", MenuItem("Optimize", 'onclick'=A3), MenuSeparator(), MenuItem("Close", 'onclick'=Shutdown()) ), # end Menu/File Menu("Help", MenuItem("Using this Maplet", 'onclick'=RunWindow('helpWin')) ) # end menu/Help ), # end MenuBar Window['mainWin']('menubar'='MB', title="Explore the maximum area of a box within a parabola intersecting the x-axis. Also, use the derivative to solve it by hand.", BoxRow ('background'="#DDFFFF", BoxColumn ('background'="#DDFFFF", BoxRow('background'="#DDFFFF", 'caption'="Enter a parabola", border='true', TextField[F]("9-x^2", 'background'="#EEFFFF") ), # end BoxRow BoxRow('background'="#DDFFFF", 'border'='true', 'caption'="Plot Window", Plotter[PL1]('background'="#EEFFFF") ) # end BoxRow ), # end BoxColumn BoxColumn('background'="#DDFFFF", BoxColumn('background'="#DDFFFF", caption="Experimentation", border=true, BoxRow('background'="#DDFFFF", BoxCell( halign='left', "Guess the width of the biggest box " ), BoxCell( halign='left', TextField[W](3, 'value'=" ",'background'="#EEFFFF") ), BoxCell(), BoxCell(Button("Plot Box", onclick='A2', 'background'="#CCFFFF")) ), # end BoxRow BoxRow('background'="#DDFFFF", BoxCell( halign='left', "Area of this box " ), BoxCell( halign='left', TextField[AREA1](value=0, not editable, 10, 'background'="#EEFFFF") ) ) # end BoxRow ), # end BoxColumn BoxColumn('background'="#DDFFFF", caption="Optimization", border=true, BoxRow('background'="#DDFFFF", BoxCell(halign='left', "Width of the biggest box " ), BoxCell( halign='center', MathMLViewer[WIDTH](height=50, width=150, 'background'="#EEFFFF" )) ), # end BoxRow BoxRow('background'="#DDFFFF", BoxCell( halign='left', "Area of the biggest box " ), BoxCell( halign='left', TextField[AREA2](value=0, not editable, 10, 'background'="#EEFFFF" )) ), # end BoxRow BoxRow('background'="#DDFFFF", BoxCell( halign='left', Button( "Optimize", onclick=A3, 'background'="#CCFFFF") ) ) # end BoxRow ), # end BoxColumn BoxRow('background'="#DDFFFF", 'spacing'=10, 'inset'=10, Button("Plot Parabola", 'background'="#CCFFFF", 'onclick'=A1 ), Button("Close", 'background'="#CCFFFF", Shutdown() ) ) # end BoxRow ) # end BoxColumn ) ) , Window['helpWin']( 'resizable'='false', 'title'="Using the Area Maximization Maplet", BoxColumn('border'='true', 'inset'=0, 'spacing'=5, 'background'="#CCFFFF", BoxCell( TextBox('height'=13, 'width'=42, 'background'="#DDFFFF", 'foreground'="#333399", 'font'='F2', 'editable'='false', 'value'=helpStr ) # end TextBox ), # end BoxCell BoxRow('inset'=0, 'spacing'=0, 'background'="#CCFFFF", Button("Close", 'background'="#CCFFFF", CloseWindow('helpWin')) ) # end BoxRow ) # end BoxColumn ), # end helpWin Action['A1'] ( Evaluate ( 'waitforresult'='false','target'='PL1','function' = 'parabInitialDraw', Argument('F',quotedtext='true') ) ), Action['A2'] ( Evaluate ( 'waitforresult'='false','target'='AREA1', 'function'='parabArea', Argument('F',quotedtext='true'), Argument('W',quotedtext='true') ), Evaluate ( 'waitforresult'='false','target'='PL1', 'function'='parabDraw', Argument('F',quotedtext='true'), Argument('W',quotedtext='true') ) ), Action['A3'] ( Evaluate ( 'target'='TF1','function' = 'parabOptWidth', Argument('F',quotedtext='true') ), Evaluate ( 'target'='WIDTH','function' = 'MathML:-Export(TF1)' ), Evaluate ( 'target'='AREA2' ,'function'= 'parabArea', Argument('F',quotedtext='true'), Argument('TF1',quotedtext='true') ), Evaluate ( 'target'='PL1' ,'function'= 'parabDraw', Argument('F',quotedtext='true'), Argument('TF1',quotedtext='true') ) ), TextField['TF1'](1) ): # end Maplet Maplets:-Display(maplet): end use: end proc: end module: # end Maplet AreaMaximiztionMaplet:-runAreaMaximization(); # Basic Curve Analysis