# 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 # Basic Curve Analysis # Click in red area and press [Enter]. # Curve Analysis Maplet # Copyright 2002 Waterloo Maple Inc. # # The Curve Analysis maplet allows the user to analyze the graph of a function using first and second derivatives. # # The user enters a function. The maplet displays the intervals over which the function is increasing, decreasing, concave or convex, or the local maximum and minimum points. # # Additionally, the user can view a plot of all intervals and points. # # To run this maplet, click the Execute (!!!) button in the context bar. # Digits:=5: CurveAnalysisMaplet := module() export DisplayOptions, PlotOptions, showFunc, showConUp, showConDown, showInc, showDec, showMax, showMin, Calc1Maplet, showConUp1, showConDown1, showInc1, showDec1, showMax1, showMin1, DisplayMax, DisplayMin, DisplayConcaveUp, DisplayConcaveDown, DisplayInc, DisplayDec, showAll, showTangent, findRoots, maplet; local helpStr; ############################################################ helpStr := "The Curve Analysis maplet allows you to analyze the graph of a function using first and second derivatives. Enter a continuous function and its domain. To display the function, select Show the Function and click the 'Show' button. To display the maximum and minimum points of this function, select Show the Local Maxima or Show the Local Minima and click the 'Show' button. To display the intervals over which the function is increasing or decreasing, select Show the Increasing Intervals or Show the Decreasing Intervals and click the 'Show' button. To display the intervals over which the function is concave or convex, select Show the Concave Up Intervals or Show the Concave Down Intervals and click the 'Show' button. To view a plot of all intervals and points, click the 'Plot All' button.": ############################################################ DisplayOptions:= proc() if Maplets:-Tools:-Get('TBh2'(value)) then DisplayMax(Maplets:-Tools:-Get(F::algebraic), Maplets:-Tools:-Get(NEGX::algebraic), Maplets:-Tools:-Get(POSX::algebraic)); elif Maplets:-Tools:-Get('TBh3'(value)) then DisplayMin(Maplets:-Tools:-Get(F::algebraic), Maplets:-Tools:-Get(NEGX::algebraic), Maplets:-Tools:-Get(POSX::algebraic)); elif Maplets:-Tools:-Get('TBh4'(value)) then DisplayInc(Maplets:-Tools:-Get(F::algebraic), Maplets:-Tools:-Get(NEGX::algebraic), Maplets:-Tools:-Get(POSX::algebraic)); elif Maplets:-Tools:-Get('TBh5'(value)) then DisplayDec(Maplets:-Tools:-Get(F::algebraic), Maplets:-Tools:-Get(NEGX::algebraic), Maplets:-Tools:-Get(POSX::algebraic)); elif Maplets:-Tools:-Get('TBh6'(value)) then DisplayConcaveUp(Maplets:-Tools:-Get(F::algebraic), Maplets:-Tools:-Get(NEGX::algebraic), Maplets:-Tools:-Get(POSX::algebraic)); elif Maplets:-Tools:-Get('TBh7'(value)) then DisplayConcaveDown(Maplets:-Tools:-Get(F::algebraic), Maplets:-Tools:-Get(NEGX::algebraic), Maplets:-Tools:-Get(POSX::algebraic)); end if; end proc: ############################################################ PlotOptions:= proc() if Maplets:-Tools:-Get('TBh1'(value)) then showFunc(Maplets:-Tools:-Get(F::algebraic), Maplets:-Tools:-Get(NEGX::algebraic), Maplets:-Tools:-Get(POSX::algebraic)); elif Maplets:-Tools:-Get('TBh2'(value)) then showMax1(Maplets:-Tools:-Get(F::algebraic), Maplets:-Tools:-Get(NEGX::algebraic), Maplets:-Tools:-Get(POSX::algebraic)); elif Maplets:-Tools:-Get('TBh3'(value)) then showMin1(Maplets:-Tools:-Get(F::algebraic), Maplets:-Tools:-Get(NEGX::algebraic), Maplets:-Tools:-Get(POSX::algebraic)); elif Maplets:-Tools:-Get('TBh4'(value)) then showInc1(Maplets:-Tools:-Get(F::algebraic), Maplets:-Tools:-Get(NEGX::algebraic), Maplets:-Tools:-Get(POSX::algebraic)); elif Maplets:-Tools:-Get('TBh5'(value)) then showDec1(Maplets:-Tools:-Get(F::algebraic), Maplets:-Tools:-Get(NEGX::algebraic), Maplets:-Tools:-Get(POSX::algebraic)); elif Maplets:-Tools:-Get('TBh6'(value)) then showConUp1(Maplets:-Tools:-Get(F::algebraic), Maplets:-Tools:-Get(NEGX::algebraic), Maplets:-Tools:-Get(POSX::algebraic)); elif Maplets:-Tools:-Get('TBh7'(value)) then showConDown1(Maplets:-Tools:-Get(F::algebraic), Maplets:-Tools:-Get(NEGX::algebraic), Maplets:-Tools:-Get(POSX::algebraic)); end if; end proc: ############################################################ use Maplets:-Elements in maplet := Maplet('onstartup'=RunWindow('mainWin'), ############################################################ Font['F1']('family'="Default", 'bold'='false', 'size'=12), Font['F2']('family'="Default", 'bold'='true', 'size'=14), ############################################################ MenuBar[MB1]( Menu("File", MenuItem("Show", 'onclick'='A1'), MenuSeparator(), MenuItem("Plot All", 'onclick'='A3'), MenuItem("Clear", 'onclick'='A4'), MenuSeparator(), MenuItem("Close", Shutdown()) ), # end menu/File Menu("Help", MenuItem("Using this Maplet", 'onclick'=RunWindow('helpWin')) ) # end menu/Help ), # end MenuBar ############################################################ Window[mainWin](title="Basic Curve Analysis: Explore using this maplet and then use derivatives to find local max/min points by hand.", height=480, width=800, menubar=MB1, 'layout' = BL1, BoxLayout[BL1](inset=0, 'background'="#DDFFFF", BoxColumn(inset=0, spacing=0, 'background'="#DDFFFF", 'caption'="Plot Window", 'border'=true, Plotter[P1]('background'="#EEFFFF") ), # end BoxColumn for Plotter BoxColumn(inset=0, spacing=0, 'background'="#DDFFFF", BoxRow(inset=0, 'caption'="Enter a differentiable function and its domain:", 'border'='true', spacing=0, 'background'="#DDFFFF", Label("Function ", 'font' = 'F1'), TextField[F]("sin(x)", 'width'=15, 'background'="#EEFFFF"), Label(" x = ", 'font' = 'F1'), BoxCell(TextField[NEGX](width=6,"-4*Pi", 'background'="#EEFFFF")), Label(" to ", 'font' = 'F1'), BoxCell(TextField[POSX](width=6,"4*Pi", 'background'="#EEFFFF")) ), # end BoxRow BoxRow('inset'=0, 'spacing'=0, 'background'="#DDFFFF", BoxColumn('inset'=0, 'spacing'=0, 'background'="#DDFFFF", RadioButton['TBh1']("Show the Function", 'background'="#DDFFFF",'group'='BG1', 'value'='true'), # end RadioButton RadioButton['TBh2']("Show the Local Maxima", 'background'="#DDFFFF",'group'='BG1' ), # end RadioButton RadioButton['TBh3']("Show the Local Minima", 'background'="#DDFFFF",'group'='BG1' ) # end RadioButton ), # end BoxColumn BoxColumn('inset'=0, 'spacing'=0, 'background'="#DDFFFF", RadioButton['TBh4']("Show the Increasing Intervals", 'background'="#DDFFFF", 'group'='BG1'), # end RadioButton RadioButton['TBh5']("Show the Decreasing Intervals", 'background'="#DDFFFF", 'group'='BG1'), # end RadioButton RadioButton['TBh6']("Show the Concave Up Intervals", 'background'="#DDFFFF",'group'='BG1'), # end RadioButton RadioButton['TBh7']("Show the Concave Down Intervals", 'background'="#DDFFFF",'group'='BG1') # end RadioButton ) # end BoxColumn ), # end BoxRow BoxRow('background'="#DDFFFF", Button("Plot your choice", 'onclick'='A1', 'background'="#EEFFFF", 'font' = 'F1' ), # end Show button ################################## Moved the Plot All Button Button[all]("Plot All", 'onclick'='A3', 'font' = 'F1', 'background'="#EEFFFF") # end Plot All button ), # end BoxRow BoxRow('caption'="Points and Intervals", border=true, inset=0, spacing=0, 'background'="#DDFFFF", MathMLViewer['T1']( 'background'="#EEFFFF") ), # end BoxRow BoxRow('background'="#DDFFFF", Button[clear]("Clear", 'onclick'='A4', 'font' = 'F1', 'background'="#EEFFFF"), # end Clear button Button[close]("Close", Shutdown(), 'font' = 'F1', 'background'="#EEFFFF") # end Close button ) # end BoxRow ) # end BoxColumn ) # end BoxLayout ), # end Window ############################################################ Window['helpWin']( 'resizable'='false', 'title'="Using the Curve Analysis Maplet", BoxColumn('border'=true, 'background'="#DDFFFF", 'inset'=0, 'spacing'=4, BoxRow('inset'=0, 'spacing'=0, 'background'="#DDFFFF", TextBox('height'=22, 'width'=36, 'background'="#DDFFFF", 'font'='F2', 'editable'='false', 'value'=helpStr, 'foreground'="#333399" ) # end TextBox ), # end BoxRow BoxRow('inset'=0, 'spacing'=0, 'background'="#DDFFFF", Button("Close", 'font'='F1', 'background'="#CCFFFF", CloseWindow('helpWin') ) ) # end BoxRow ) # end BoxColumn ), # end helpWin ############################################################ ButtonGroup['BG1'](), Action['A1'](Evaluate('T1'='DisplayOptions'), Evaluate('P1'='PlotOptions') ), # end A1 Action['A3'](Evaluate(P1='showAll(F, NEGX, POSX)'), SetOption('T1'="") ), # end A2 Action['A4'](SetOption('F'=""), SetOption('NEGX'=""), SetOption('POSX'=""), SetOption('T1'=""), Evaluate('P1' = plot(undefined, x = 0..10)) ) # end A3 ): end use: ############################################################ ############################################################ showFunc := proc(f, negX, posX) option remember: plot(f, x=negX..posX, color=black, thickness=3): end proc: showConUp1 := proc(f, negX, posX) option remember: plots[display](showConUp(f, negX, posX), showFunc(f, negX, posX)): end proc: showConDown1 := proc(f, negX, posX) option remember: plots[display](showConDown(f, negX, posX), showFunc(f, negX, posX)): end proc: showInc1 := proc(f, negX, posX) option remember: plots[display](showInc(f, negX, posX), showFunc(f, negX, posX)): end proc: showDec1 := proc(f, negX, posX) option remember: plots[display](showDec(f, negX, posX), showFunc(f, negX, posX)): end proc: showMax1 := proc(f, negX, posX) option remember: plots[display](showMax(f, negX, posX), showFunc(f, negX, posX)): end proc: showMin1 := proc(f, negX, posX) option remember: plots[display](showMin(f, negX, posX), showFunc(f, negX, posX)): end proc: ############################################################ showConUp := proc(f, negX, posX) option remember: local d2, sols, i, n, polys, j, delta, X1, X2, Y1, Y2, p: d2 := diff(f,x$2); sols := findRoots(d2, negX, posX); if not member(evalf(negX), sols) then sols := [evalf(negX), op(sort(sols))]: end if: if not member(evalf(posX), sols) then sols := [op(sort(sols)), evalf(posX)]: end if: n := 100: polys := []: for j from 1 to (nops(sols) - 1) do if evalf(subs(x = (sols[j] + sols[j+1])/2, d2)) > 0 then delta := (sols[j+1] - sols[j]) / n: X2 := sols[j]: for i from 1 to n do X1 := evalf(X2): Y1 := evalf(subs(x = X1, f)): X2 := evalf(sols[j] + i * delta): Y2 := evalf(subs(x=X2,f)): p[i] := plots[polygonplot]([[X1, 0],[X1, Y1],[X2, Y2],[X2, 0]], color=plum, style=patchnogrid): end do: polys := [op(polys), seq(p[i],i=1..n)]: end if: end do: if nops(polys) = 0 then return NULL: end if: plots[display](seq(polys[i],i=1..nops(polys))): end proc: ############################################################ showConDown := proc(f, negX, posX) option remember: local d2, sols, i, n, polys, j, delta, X1, X2, Y1, Y2, p: d2 := diff(f,x$2); sols := findRoots(d2, negX, posX); if not member(evalf(negX), sols) then sols := [evalf(negX), op(sort(sols))]: end if: if not member(evalf(posX), sols) then sols := [op(sort(sols)), evalf(posX)]: end if: n := 100: polys := []: for j from 1 to (nops(sols) - 1) do if evalf(subs(x = (sols[j] + sols[j+1])/2, d2)) < 0 then delta := (sols[j+1] - sols[j]) / n: X2 := sols[j]: for i from 1 to n do X1 := evalf(X2): Y1 := evalf(subs(x=X1,f)): X2 := evalf(sols[j] + i * delta): Y2 := evalf(subs(x=X2,f)): p[i] := plots[polygonplot]([[X1, 0],[X1, Y1],[X2, Y2],[X2, 0]], color=pink, style=patchnogrid): end do: polys := [op(polys), seq(p[i],i=1..n)]: end if: end do: if nops(polys) = 0 then return NULL: end if: plots[display](seq(polys[i],i=1..nops(polys))): end proc: ############################################################ showInc := proc(f, negX, posX) option remember: local d1, sols, i, lines, j: d1 := diff(f,x); sols := findRoots(d1, negX, posX); if not member(evalf(negX), sols) then sols := [evalf(negX), op(sort(sols))]: end if: if not member(evalf(posX), sols) then sols := [op(sort(sols)), evalf(posX)]: end if: lines := []: for j from 1 to (nops(sols) - 1) do if evalf(subs(x=(sols[j]+sols[j+1])/2,d1)) > 0 then lines := [op(lines), plot(f, x=sols[j]..sols[j+1], color=blue, thickness=3)]: end if: end do: if nops(lines) = 0 then return NULL: end if: plots[display](seq(lines[i],i=1..nops(lines))): end proc: ############################################################ showDec := proc(f, negX, posX) option remember: local d1, sols, i, lines, j: d1 := diff(f,x); sols := findRoots(d1, negX, posX); if not member(evalf(negX), sols) then sols := [evalf(negX), op(sort(sols))]: end if: if not member(evalf(posX), sols) then sols := [op(sort(sols)), evalf(posX)]: end if: lines := []: for j from 1 to (nops(sols) - 1) do if evalf(subs(x=(sols[j] + sols[j+1])/2,d1)) < 0 then lines := [op(lines), plot(f, x=sols[j]..sols[j+1], color=red, thickness=3)]: end if: end do: if nops(lines) = 0 then return NULL: end if: plots[display](seq(lines[i],i=1..nops(lines))): end proc: ############################################################ showMax := proc(f, negX, posX) option remember: local d1, d2, sols, i, p: d1 := diff(f,x); d2 := diff(f,x$2); sols := DisplayMax(f, negX, posX); p := []: for i from 1 to nops(sols) do if evalf(subs(x=sols[i][1],d2)) < 0 then p := [op(p), plottools[line]([sols[i][1],0],[sols[i][1],subs(x=sols[i][1], f)], color=blue, thickness=3)]: end if: end do: if nops(p) = 0 then return NULL: end if: plots[display](seq(p[i],i=1..nops(p))): end proc: ############################################################ showMin := proc(f, negX, posX) option remember: local d1, d2, sols, i, p: d1 := diff(f,x); d2 := diff(f,x$2); sols := DisplayMin(f, negX, posX); p := []: for i from 1 to nops(sols) do if evalf(subs(x=sols[i][1],d2)) > 0 then p := [op(p), plottools[line]([sols[i][1],0],[sols[i][1],subs(x=sols[i][1], f)],color=red,thickness=3)]: end if: end do: if nops(p) = 0 then return NULL: end if: plots[display](seq(p[i],i=1..nops(p))): end proc: ############################################################ DisplayMax:=proc(f, negX, posX) local Max, CritPoints, i, Diffunc; Max:=[]: CritPoints:=Student:-Calculus1:-CriticalPoints(f, x=negX..posX): Diffunc:=diff(f, x): if CritPoints = [] then CritPoints:=Student:-Calculus1:-CriticalPoints(f, numeric, x=negX..posX): end if; if CritPoints <> [] then for i from 1 to nops(CritPoints) do if i<>nops(CritPoints) and evalf(subs(x=(CritPoints[i+1]+CritPoints[i])/2, Diffunc))<0 then Max:=[op(Max), [CritPoints[i], value(subs(x=CritPoints[i], f))]]; elif i=nops(CritPoints) and evalf(subs(x=((posX+CritPoints[nops(CritPoints)])/2), Diffunc))<0 then Max:=[op(Max), [CritPoints[i], value(subs(x=CritPoints[i], f))]]; end if; end do; end if; Max; end proc: ############################################################ DisplayMin:=proc(f, negX, posX) local Min, CritPoints, i, Diffunc; Min:=[]: CritPoints:=Student:-Calculus1:-CriticalPoints(f, x=negX..posX): Diffunc:=diff(f, x): if CritPoints = [] then CritPoints:=Student:-Calculus1:-CriticalPoints(f, numeric, x=negX..posX): end if; if CritPoints <> [] then for i from 1 to nops(CritPoints) do if i<>nops(CritPoints) and evalf(subs(x=(CritPoints[i+1]+CritPoints[i])/2, Diffunc))>0 then Min:=[op(Min), [CritPoints[i], value(subs(x=CritPoints[i], f))]]; elif i=nops(CritPoints) and evalf(subs(x=((posX+CritPoints[nops(CritPoints)])/2), Diffunc))>0 then Min:=[op(Min), [CritPoints[i], value(subs(x=CritPoints[i], f))]]; end if; end do; end if; Min; end proc: ############################################################ DisplayInc:=proc(f, negX, posX) local Inc, Points, d1, i; Inc:=[]: d1:=diff(f, x): Points:=Student:-Calculus1:-CriticalPoints(f, x=negX..posX): if Points = [] then Points:=Student:-Calculus1:-CriticalPoints(f, numeric, x=negX..posX): end if; if Points <> [] then for i from 1 to nops(Points) do if i=1 and evalf(subs(x=((Points[i]+negX)/2), d1))>0 and negX <> Points[1] then Inc:=[op(Inc), [negX, Points[i]]]; elif evalf(subs(x=Points[i]+0.1, d1))>0 and i <> nops(Points) then Inc:=[op(Inc), [Points[i],Points[i+1]]]; elif i=nops(Points) and evalf(subs(x=((posX+Points[nops(Points)])/2), d1))>0 and Points[i]<> posX then Inc:=[op(Inc), [Points[i], posX]]; end if; end do; end if; Inc; end proc: ############################################################ DisplayDec:=proc(f, negX, posX) local Dec, Points, d1, i; Dec:=[]: d1:=diff(f, x): Points:=Student:-Calculus1:-CriticalPoints(f, x=negX..posX): if Points = [] then Points:=Student:-Calculus1:-CriticalPoints(f, numeric, x=negX..posX): end if; if Points <> [] then for i from 1 to nops(Points) do if i=1 and evalf(subs(x=((Points[1]+negX)/2), d1))<0 and negX <> Points[1] then Dec:=[op(Dec), [negX, Points[i]]]; elif evalf(subs(x=Points[i]+0.1, d1))<0 and i <> nops(Points) then Dec:=[op(Dec), [Points[i], Points[i+1]]]; elif i=nops(Points) and evalf(subs(x=((posX+Points[nops(Points)])/2), d1))<0 and posX <> Points[i] then Dec:=[op(Dec), [Points[i], posX]]; end if; end do; end if; Dec; end proc: ############################################################ DisplayConcaveUp:=proc(f, negX, posX) local ConcaveUp, Points, d1, i; ConcaveUp:=[]: d1:=diff(f, x$2): Points:=Student:-Calculus1:-InflectionPoints(f, x=negX..posX): for i from 1 to nops(Points) do if i=1 and evalf(subs(x=((Points[1]+negX)/2), d1))>0 and negX <> Points[1] then if type(Points[i], RootOf) then ConcaveUp:=[op(ConcaveUp), [negX, evalf(Points[i])]]; else ConcaveUp:=[op(ConcaveUp), [negX, Points[i]]]; end if; elif evalf(subs(x=Points[i]+0.1, d1))>0 and i <> nops(Points) then if type(Points[i], RootOf) then ConcaveUp:=[op(ConcaveUp), [evalf(Points[i]), evalf(Points[i+1])]]; else ConcaveUp:=[op(ConcaveUp), [Points[i], Points[i+1]]]; end if; elif i=nops(Points) and evalf(subs(x=((posX+Points[i])/2), d1))>0 and posX <> Points[i] then if type(Points[i], RootOf) then ConcaveUp:=[op(ConcaveUp), [evalf(Points[i]), posX]]; else ConcaveUp:=[op(ConcaveUp), [Points[i], posX]]; end if; end if; end do; if nops(Points)=0 then Points:=Student:-Calculus1:-CriticalPoints(f, x=negX..posX); if evalf(subs(x=((posX+Points[1])/2), d1))>0 then ConcaveUp:=[negX, posX]; end if; end if; ConcaveUp; end proc: ############################################################ DisplayConcaveDown:=proc(f, negX, posX) local ConcaveDown, Points, d1, i; ConcaveDown:=[]: d1:=diff(f, x$2): Points:=Student:-Calculus1:-InflectionPoints(f, x=negX..posX): for i from 1 to nops(Points) do if i=1 and evalf(subs(x=((Points[1]+negX)/2), d1))<0 and negX <> Points[1] then if type(Points[i], RootOf) then ConcaveDown:=[op(ConcaveDown), [negX, evalf(Points[i])]]; else ConcaveDown:=[op(ConcaveDown), [negX, Points[i]]]; end if; elif evalf(subs(x=Points[i]+0.1, d1))<0 and i <> nops(Points) then if type(Points[i], RootOf) then ConcaveDown:=[op(ConcaveDown), [evalf(Points[i]), evalf(Points[i+1])]]; else ConcaveDown:=[op(ConcaveDown), [Points[i], Points[i+1]]]; end if; elif i=nops(Points) and evalf(subs(x=((posX+Points[nops(Points)])/2), d1))<0 and posX <> Points[i] then if type(Points[i], RootOf) then ConcaveDown:=[op(ConcaveDown), [evalf(Points[i]), posX]]; else ConcaveDown:=[op(ConcaveDown), [Points[i], posX]]; end if; end if; end do; if nops(Points)=0 then Points:=Student:-Calculus1:-CriticalPoints(f, x=negX..posX); if evalf(subs(x=((posX+Points[1])/2), d1))<0 then ConcaveDown:=[negX, posX]; end if; end if; ConcaveDown; end proc: ############################################################ showTangent := proc(f, negX, posX); plots[display](Student:-Calculus1:-MeanValueTheorem(f, x=negX..posX, showfunction=false, showpoints=false, showline=false, title=` `, tangentoptions=[thickness=3, color=green], tangentlength=0.5), showFunc(f, negX, posX)); end proc: ############################################################ showAll := proc(f, negX, posX) option remember: plots[display](showMin(f, negX, posX), showMax(f, negX, posX), showConDown(f, negX, posX), showConUp(f, negX, posX), showDec(f, negX, posX), showInc(f, negX, posX)): end proc: ############################################################ findRoots := proc(f, negX, posX) option remember: local n, i, delta, li, X1, X2, sol, IN, j: n := 100: li := []: delta := (evalf(posX) - evalf(negX)) / n: X2 := evalf(negX): for i from 1 to n do X1 := evalf(X2): X2 := evalf(negX + i * delta): sol := fsolve(f = 0, x=X1..X2): if type(sol, numeric) then if not member(sol, li) then li := [ op(li), sol]: end if: end if: end do: li; end proc: Maplets:-Display(maplet); end module: ############################################################ #CurveAnalysisMaplet:-Calc1Maplet(): #Maplets:-Display(CurveAnalysisMaplet:-maplet):