# Micheal Bass and Will Woodruff # Concavity of Functions from the Sign of the Second Derivative # Math 152 Honors Section 201 # Spring 2012 # Instructor: Philip Yasskin restart: with(Maplets[Tools]): with(Maplets[Elements]): with(plots): StartEngine(); randomize(): rand4:=rand(0..4): randpm4:=rand(-4..4): rand1:=rand(0..1): p0:=plot(0, x=-5..5, -0.1..0.1, scaling=constrained, tickmarks=[11,0], color=black): ask:=proc() global e, direction,second_derivative_factored, second_derivative, first_derivative, function1, z1, z2, p1; local a,b,c,d; a:=rand4(); b:=randpm4(); c:=rand4(); d:=randpm4(); if a=0 then a:=1; end if: if c=0 then c:=1; end if: e:=rand1(); if e=0 then direction:="up"; else direction:="down"; end if; Set(LProb(caption)=sprintf("Determine all intervals where the following function is concave %s.",direction)); second_derivative_factored:= (a*x+b)*(c*x+d); second_derivative:= sort(expand(second_derivative_factored)); first_derivative:= int(second_derivative,x); function1:=int(first_derivative,x); z1:=-d/c; z2:=-b/a; if z1 > z2 then z1,z2:=z2,z1; end if; p1:=plot([[z1,0],[z2,0]], style=point, view=[-5..5,-0.1..0.1], scaling=constrained, tickmarks=[11,0], symbol=solidcircle, symbolsize=30); Set(question=function1); Set(answer1a=""); Set(answer1b=""); Set(answer2=""); Set(PLine=p0); Set(RB1p=false); Set(RB1m=false); Set(RB2p=false, RB2p(visible)=true); Set(RB2m=false, RB2m(visible)=true); Set(RB3p=false); Set(RB3m=false); Set(LInt1(caption)=sprintf("(-infinity,%a)",'a')); Set(LInt2(caption)=sprintf("(%a,%a)",'a','b'), LInt2(visible)=true); Set(LInt3(caption)=sprintf("(%a,infinity)",'b')); Set(reply3=(""), reply3(background)=white); Set(CBConcave1=false); Set(CBConcave2=false, CBConcave2(visible)=true); Set(CBConcave3=false); Set(Concave1(caption)=sprintf("(-infinity,%a)",'a')); Set(Concave2(caption)=sprintf("(%a,%a)",'a','b'), Concave2(visible)=true); Set(Concave3(caption)=sprintf("(%a,infinity)",'b')); Set(reply4=(""), reply4(background)=white); Set(reply=(""), reply(background)=white); end proc: check1a:=proc() global first_derivative; local user_answer1a; user_answer1a:=Get(answer1a::algebraic, corrections=true, update=true): if user_answer1a=first_derivative then Set(reply="Correct! Try another question.", reply(background)=green, reply(foreground)=black); else Set(reply="Incorrect. Try again.", reply(background)=red, reply(foreground)=white); end if; end proc: show1a:=proc() global first_derivative; Set(answer1a=first_derivative): Set(reply="Next time try doing it yourself.", reply(background)=yellow, reply(foreground)=black); end proc: check1b:=proc() global second_derivative; local user_answer1b; user_answer1b:=Get(answer1b::algebraic, corrections=true, update=true): if user_answer1b=second_derivative then Set(reply="Correct! Try another question.", reply(background)=green, reply(foreground)=black) else Set(reply="Incorrect. Try again.", reply(background)=red, reply(foreground)=white) end if; end proc: show1b:=proc() global second_derivative; Set(answer1b=second_derivative): Set(reply="Next time try doing it yourself.", reply(background)=yellow, reply(foreground)=black); end proc: check2:=proc() global z1, z2; local user_answer2; user_answer2:=Get(answer2::anything, corrections=true, update=true): if {user_answer2}={z1, z2} then Set(reply="Correct! Try another question.", reply(background)=green, reply(foreground)=black); if z1=z2 then Set(answer2=z1): Set(RB2p(visible)=false); Set(RB2m(visible)=false); Set(LInt2(visible)=false); Set(CBConcave2(visible)=false); Set(Concave2(visible)=false); else Set(answer2=sprintf("%a, %a",z1,z2)): end if; Set(LInt1(caption)=sprintf("(-infinity,%a)",z1)); Set(LInt2(caption)=sprintf("(%a,%a)",z1,z2)); Set(LInt3(caption)=sprintf("(%a,infinity)", z2)); Set(Concave1(caption)=sprintf("(-infinity,%a)",z1)); Set(Concave2(caption)=sprintf("(%a,%a)",z1,z2)); Set(Concave3(caption)=sprintf("(%a,infinity)",z2)); Set(PLine=p1); else Set(reply="Incorrect. Try again.", reply(background)=red, reply(foreground)=white) end if; end proc: show2:=proc() global z1,z2; if z1=z2 then Set(answer2=z1): Set(RB2p(visible)=false); Set(RB2m(visible)=false); Set(LInt2(visible)=false); Set(CBConcave2(visible)=false); Set(Concave2(visible)=false); else Set(answer2=sprintf("%a, %a",z1,z2)): end if; Set(LInt1(caption)=sprintf("(-infinity,%a)",z1)); Set(LInt2(caption)=sprintf("(%a,%a)",z1,z2)); Set(LInt3(caption)=sprintf("(%a,infinity)", z2)); Set(Concave1(caption)=sprintf("(-infinity,%a)",z1)); Set(Concave2(caption)=sprintf("(%a,%a)",z1,z2)); Set(Concave3(caption)=sprintf("(%a,infinity)",z2)); Set(PLine=p1); Set(reply="Next time try doing it yourself.", reply(background)=yellow, reply(foreground)=black); end proc: check3:=proc() global z1,z2,p1; local user_Int1p, user_Int2p, user_Int3p, user_Int1m,user_Int2m, user_Int3m, ncorrect; ncorrect:=0; user_Int1p:=Get(RB1p::truefalse); user_Int2p:=Get(RB2p::truefalse); user_Int3p:=Get(RB3p::truefalse); user_Int1m:=Get(RB1m::truefalse); user_Int2m:=Get(RB2m::truefalse); user_Int3m:=Get(RB3m::truefalse); if (subs(x=(z1-1), second_derivative)>0 and user_Int1p) or (subs(x=(z1-1), second_derivative)<0 and user_Int1m) then ncorrect:=ncorrect+1; end if; if (subs(x=(z2+1), second_derivative)>0 and user_Int3p) or (subs(x=(z2+1), second_derivative)<0 and user_Int3m) then ncorrect:=ncorrect+1; end if; if z1=z2 then if ncorrect=2 then Set(reply3=("Correct"), reply3(background)=green, reply3(foreground)=black); Set(reply="Correct! Try another question.", reply(background)=green, reply(foreground)=black) else Set(reply3=("Incorrect"), reply3(background)=red, reply3(foreground)=white); Set(reply=sprintf("You have %a correct and %a wrong.", ncorrect, 2-ncorrect), reply(background)=red, reply(foreground)=white); end if; else if (subs(x=(z1+z2)/2, second_derivative)>0 and user_Int2p) or (subs(x=(z1+z2)/2, second_derivative)<0 and user_Int2m) then ncorrect:=ncorrect+1; end if; if ncorrect=3 then Set(reply3=("Correct"), reply3(background)=green, reply3(foreground)=black); Set(reply="Correct! Try another question.", reply(background)=green, reply(foreground)=black) else Set(reply3=("Incorrect"), reply3(background)=red, reply3(foreground)=white); Set(reply=sprintf("You have %a correct and %a wrong.", ncorrect, 3-ncorrect), reply(background)=red, reply(foreground)=white); end if; end if; end proc: show3:=proc() global z1,z2, p1; if (subs(x=(z1-1),second_derivative))>0 then Set(RB1p=true); else Set(RB1m=true); end if; if (subs(x=((z1+z2)/2),second_derivative))>0 then Set(RB2p=true); else Set(RB2m=true); end if; if (subs(x=(z2+1),second_derivative))>0 then Set(RB3p=true); else Set(RB3m=true); end if; Set(reply3=("Shown"), reply3(background)=yellow, reply3(foreground)=black); Set(reply="Next time try doing it yourself.", reply(background)=yellow, reply(foreground)=black); end proc: check4:=proc() local user_Concave1, user_Concave2, user_Concave3, ncorrect; ncorrect:=0; user_Concave1:=Get(CBConcave1::truefalse); user_Concave2:=Get(CBConcave2::truefalse); user_Concave3:=Get(CBConcave3::truefalse); if e = 0 then if (subs(x=(z1-1), second_derivative)>0 and user_Concave1) or (subs(x=(z1-1), second_derivative)<0 and not user_Concave1) then ncorrect:=ncorrect+1; end if; if (subs(x=(z2+1), second_derivative)>0 and user_Concave3) or (subs(x=(z2+1), second_derivative)<0 and not user_Concave3) then ncorrect:=ncorrect+1; end if; if z1=z2 then if ncorrect=2 then Set(reply4=("Correct"), reply4(background)=green, reply4(foreground)=black); Set(reply="Correct! Try another question.", reply(background)=green, reply(foreground)=black); else Set(reply4=("Incorrect"), reply4(background)=red, reply4(foreground)=white); Set(reply=sprintf("You have %a correct and %a wrong.", ncorrect, 2-ncorrect), reply(background)=red, reply(foreground)=white); end if; else if (subs(x=(z1+z2)/2, second_derivative)>0 and user_Concave2) or (subs(x=(z1+z2)/2, second_derivative)<0 and not user_Concave2)then ncorrect:=ncorrect+1; end if; if ncorrect=3 then Set(reply4=("Correct"), reply4(background)=green, reply4(foreground)=black); Set(reply="Correct! Try another question.", reply(background)=green, reply(foreground)=black); else Set(reply4=("Incorrect"), reply4(background)=red, reply4(foreground)=white); Set(reply=sprintf("You have %a correct and %a wrong.", ncorrect, 3-ncorrect), reply(background)=red, reply(foreground)=white); end if; end if; end if; if e = 1 then if (subs(x=(z1-1), second_derivative)<0 and user_Concave1) or (subs(x=(z1-1), second_derivative)>0 and not user_Concave1) then ncorrect:=ncorrect+1; end if; if (subs(x=(z2+1), second_derivative)<0 and user_Concave3) or (subs(x=(z2+1), second_derivative)>0 and not user_Concave3) then ncorrect:=ncorrect+1; end if; if z1=z2 then if ncorrect=2 then Set(reply4=("Correct"), reply4(background)=green, reply4(foreground)=black); Set(reply="Correct! Try another question.", reply(background)=green, reply(foreground)=black); else Set(reply4=("Incorrect"), reply4(background)=red, reply4(foreground)=white); Set(reply=sprintf("You have %a correct and %a wrong.", ncorrect, 2-ncorrect), reply(background)=red, reply(foreground)=white); end if; else if (subs(x=(z1+z2)/2, second_derivative)<0 and user_Concave2) or (subs(x=(z1+z2)/2, second_derivative)>0 and not user_Concave2)then ncorrect:=ncorrect+1; end if; if ncorrect=3 then Set(reply4=("Correct"), reply4(background)=green, reply4(foreground)=black); Set(reply="Correct! Try another question.", reply(background)=green, reply(foreground)=black); else Set(reply4=("Incorrect"), reply4(background)=red, reply4(foreground)=white); Set(reply=sprintf("You have %a correct and %a wrong.", ncorrect, 3-ncorrect), reply(background)=red, reply(foreground)=white); end if; end if; end if; end proc: show4:=proc() if e=0 then if (subs(x=(z1-1),second_derivative))>0 then Set(CBConcave1=true); else Set(CBConcave1=false); end if; if (subs(x=((z1+z2)/2),second_derivative))>0 then Set(CBConcave2=true); else Set(CBConcave2=false); end if; if (subs(x=(z2+1),second_derivative))>0 then Set(CBConcave3=true); else Set(CBConcave3=false); end if; end if; if e=1 then if (subs(x=(z1-1),second_derivative))<0 then Set(CBConcave1=true); else Set(CBConcave1=false); end if; if (subs(x=((z1+z2)/2),second_derivative))<0 then Set(CBConcave2=true); else Set(CBConcave2=false); end if; if (subs(x=(z2+1),second_derivative))<0 then Set(CBConcave3=true); else Set(CBConcave3=false); end if; end if; Set(reply4=("Shown"), reply4(background)=yellow, reply4(foreground)=black); Set(reply="Next time try doing it yourself.", reply(background)=yellow, reply(foreground)=black); end proc: hint1a:=proc() Set(reply="Take the derivative of the function.", reply(background)="Orange", reply(foreground)=black); end proc: hint1b:=proc() Set(reply="Take the derivative of the first derivative.", reply(background)="Orange", reply(foreground)=black); end proc: hint2:=proc() Set(reply="Factor the polynomial.", reply(background)="Orange", reply(foreground)=black); end proc: hint3:=proc() Set(reply="Evaluate the second derivative at a test point in each the interval.", reply(background)="Orange", reply(foreground)=black); end proc: hint4:=proc() if e=0 then Set(reply="On which intervals is the second derivative positive?", reply(background)="Orange", reply(foreground)=black); else Set(reply="On which intervals is the second derivative negative?", reply(background)="Orange", reply(foreground)=black); end if; end proc: Concavity:=Maplet(onstartup = RunWindow(MAIN), Window[MAIN](title="Concavity of Functions from the Sign of the Second Derivative", [ [ Button("New Function", Evaluate(function = "ask"), background=magenta), HorizontalGlue(), [ valign=none, inset=0, spacing=0, border=true, caption="Problem Statement:", [ halign=none, Label[LProb]("Determine all intervals where the following function is concave down."), HorizontalGlue() ], [ halign=none, "f(x) =", TextField[question](width=30, editable=false, background=white), HorizontalGlue() ] ], HorizontalGlue(), Button("Quit", Shutdown(), background=pink) ], BoxColumn( valign=none, inset=0, spacing=0, border=true, caption="Step 1: Find the first and second derivatives:", [ halign=none, "f'(x) =", TextField[answer1a](width=25, background=turquoise), HorizontalGlue(), Button("Hint", Evaluate(function = "hint1a"), background=Orange), Button("Check", Evaluate(function = "check1a"), background=green), Button("Show", Evaluate(function = "show1a"), background=yellow) ], [ halign=none, "f''(x) =", TextField[answer1b](width=25, background=turquoise), HorizontalGlue(), Button("Hint", Evaluate(function = "hint1b"), background=Orange), Button("Check", Evaluate(function = "check1b"), background=green), Button("Show", Evaluate(function = "show1b"), background=yellow) ] ), BoxColumn( valign=none, inset=0, spacing=0, border=true, caption="Step 2: Solve f'' = 0:", [ halign=none, "x = ", TextField[answer2](width=25, background=turquoise), HorizontalGlue(), Button("Hint", Evaluate(function = "hint2"), background=Orange), Button("Check", Evaluate(function = "check2"), background=green), Button("Show", Evaluate(function = "show2"), background=yellow) ], "The zeroes appear on this number line.", [ halign=none, HorizontalGlue(), Plotter[PLine](width=400, height=50), HorizontalGlue() ] ), [ border=true, halign=none, caption="Step 3: Determine the sign of the second derivative on each interval.", [ valign=none, inset=0, spacing=0, [ RadioButton[RB1p]("+", group=BG1, background=turquoise), RadioButton[RB1m]("-", group=BG1, background=turquoise) ], Label[LInt1](sprintf("(-infinity,%a)",'b')) ], [ valign=none, inset=0, spacing=0, [ RadioButton[RB2p]("+", group=BG2, background=turquoise), RadioButton[RB2m]("-", group=BG2, background=turquoise) ], Label[LInt2](sprintf("(%a,%a)",'a','b')) ], [ valign=none, inset=0, spacing=0, [ RadioButton[RB3p]("+", group=BG3, background=turquoise), RadioButton[RB3m]("-", group=BG3, background=turquoise) ], Label[LInt3](sprintf("(%a,infinity)",'a')) ], HorizontalGlue(), Button("Hint",Evaluate(function = "hint3"),background="Orange"), Button("Check",Evaluate(function="check3"),background=green), TextField[reply3](width=7, editable=false, background=white), Button("Show",Evaluate(function="show3"),background=yellow) ], [ border=true, halign=none, caption="Step 4: Select the interval(s) with the desired concavity:", [ CheckBox[CBConcave1](background=turquoise), Label[Concave1](sprintf("(-infinity,%a)",'a')) ], [ CheckBox[CBConcave2](background=turquoise), Label[Concave2](sprintf("(%a,%a)",'a','b')) ], [ CheckBox[CBConcave3](background=turquoise), Label[Concave3](sprintf("(%a,infinity)",'b')) ], HorizontalGlue(), Button("Hint",Evaluate(function = "hint4"),background="Orange"), Button("Check", Evaluate(function="check4"), background=green), TextField[reply4](width=7, editable=false, background=white), Button("Show", Evaluate(function="show4"), background=yellow) ], [ TextBox[reply](width=50, height=2, editable=false, background=white) ], [ inset=0, spacing=0, "Instructor: Philip Yasskin", "Programmers: Micheal Bass & Will Woodruff", "Copyright: Yasskin 2012" ] ] ), ButtonGroup[BG1](), ButtonGroup[BG2](), ButtonGroup[BG3]() ): Maplets[Display]( Concavity );