# Devon Hillman & Paige Petersen # Increasing or Decreasing Functions from the Sign of the Derivative # Math 151 Honors Section 202 # Spring 2012 # Instructor: Philip Yasskin restart: with(Maplets[Tools]): with (Maplets[Elements]): with(plots): StartEngine(); randomize(): ##### Procedures ##### possroots:=[-5,-4,-3,-2,-1,1,2,3,4,5]: randac:=rand(6..7): randbd:=rand(1..10): randconst:=rand(-10..10): dirs:=["increasing","decreasing"]: randdir:=rand(1..2): randsgn:=rand(0..1): randpwr:=rand(1..2): p0:=plot(0, x=-7..7, -0.1..0.1, scaling=constrained, tickmarks=[15,0], color=black): NewFunction:=proc() global x1, x2, x3, der, dir, fact, fcn, p0, p1, TestInt1, TestInt2, TestInt3, TestInt4; local a,b,c,d, const; a:=possroots[randac()]; b:=possroots[randbd()]; c:=possroots[randac()]; d:=possroots[randbd()]; while b/a=d/c do a:=possroots[randac()]; b:=possroots[randbd()]; c:=possroots[randac()]; d:=possroots[randbd()]; end do; x1,x2,x3:=op(sort([b/a,d/c,0])); const:=randconst(); fact:=(a*x-b)*((c*x-d))*(x^randpwr()); der:=expand(fact); fcn:=int(der, x) + const; Set(TFfunction=fcn); dir:=randdir(); Set(Lprob(caption)=sprintf("Find the intervals on which the following function is %s.",dirs[dir])); Set(Lstep5(caption)=sprintf("%s:",dirs[dir])); TestInt1:=subs(x=x1-1, der); TestInt2:=subs(x=(x1+x2)/2, der); TestInt3:=subs(x=(x2+x3)/2, der); TestInt4:=subs(x=x3+1, der); Set(replyder=(""),replyder(background)=white); Set(replyfact=(""),replyfact(background)=white); Set(replyxs=(""),replyxs(background)=white); Set(replyInts=(""),replyInts(background)=white); Set(replyAns=(""),replyAns(background)=white); Set(reply=(""),reply(background)=white); Set(TFder=("")); Set(TFfact=("")); Set(TFxs=("")); Set(RB1p=false); Set(RB1m=false); Set(RB2p=false); Set(RB2m=false); Set(RB3p=false); Set(RB3m=false); Set(RB4p=false); Set(RB4m=false); Set(CBInt1=false); Set(CBInt2=false); Set(CBInt3=false); Set(CBInt4=false); Set(LInt1(caption)=sprintf("(-infinity,%a)",'a')); Set(LInt2(caption)=sprintf("(%a,%a)",'a','b')); Set(LInt3(caption)=sprintf("(%a,%a)",'b','c')); Set(LInt4(caption)=sprintf("(%a,infinity)",'c')); Set(Int1(caption)=sprintf("(-infinity,%a)",'a')); Set(Int2(caption)=sprintf("(%a,%a)",'a','b')); Set(Int3(caption)=sprintf("(%a,%a)",'b','c')); Set(Int4(caption)=sprintf("(%a,infinity)",'c')); Set(PLine=p0); p1:=plot([[x1,0], [x2,0], [x3,0]], style=point, view=[-7..7,-0.1..0.1], scaling=constrained, tickmarks=[15,0], symbol=solidcircle, symbolsize=30); end proc: Checkder:=proc() global x1, x2, x3, der, dir, fact, fcn, p1, p0; local user_der; user_der:=Get(TFder::anything, corrections=true, update=true); if user_der=der then Set(replyder=("Correct"), replyder(background)=green, replyder(foreground)=black); Set(reply=("Nice job. Keep going."), reply(background)=green, reply(foreground)=black); else Set(replyder=("Incorrect"), replyder(background)=red, replyder(foreground)=white); Set(reply=("Check your derivative rules and try again."), reply(background)=red, reply(foreground)=white); end if; end proc: Showder:=proc() global x1, x2, x3, der, dir, fact, fcn, p1, p0; Set(TFder=sprintf("%a",der)): Set(replyder=("Shown"), replyder(background)=yellow, replyder(foreground)=black); Set(reply=("Next time try it on your own."), reply(background)=yellow, reply(foreground)=black); end proc: Checkfact:=proc() global x1, x2, x3, der, dir, fact, fcn, p1, p0; local user_fact; user_fact:=Get(TFfact::anything, corrections=true, update=true); if user_fact=fact then Set(replyfact=("Correct"), replyfact(background)=green, replyfact(foreground)=black); Set(reply=("Your factoring abilities amaze me."), reply(background)=green, reply(foreground)=black); else Set(replyfact=("Incorrect"), replyfact(background)=red, replyfact(foreground)=white); Set(reply=("Check your answer by expanding it and try again."), reply(background)=red, reply(foreground)=white); end if; end proc: Showfact:=proc() global x1, x2, x3, der, dir, fact, fcn, p1, p0; Set(TFfact=fact): Set(replyfact=("Shown"), replyfact(background)=yellow, replyfact(foreground)=black); Set(reply=("Next time try it on your own."), reply(background)=yellow, reply(foreground)=black); end proc: Checkxs:=proc() global x1, x2, x3, der, dir, fact, fcn, p1, p0; local user_xs; user_xs:=sort([Get(TFxs::anything,corrections=true, update=true)]); if user_xs=[x1, x2, x3] then Set(replyxs=("Correct"), replyxs(background)=green, replyxs(foreground)=black); Set(reply=("Xtraordinary!! You're on a roll."), reply(background)=green, reply(foreground)=black); Set(PLine=p1); Set(LInt1(caption)=sprintf("(-infinity,%a)",x1)); Set(LInt2(caption)=sprintf("(%a,%a)",x1,x2)); Set(LInt3(caption)=sprintf("(%a,%a)",x2,x3)); Set(LInt4(caption)=sprintf("(%a,infinity)",x3)); Set(Int1(caption)=sprintf("(-infinity,%a)",x1)); Set(Int2(caption)=sprintf("(%a,%a)",x1,x2)); Set(Int3(caption)=sprintf("(%a,%a)",x2,x3)); Set(Int4(caption)=sprintf("(%a,infinity)",x3)); else Set(replyxs=("Incorrect"), replyxs(background)=red, replyxs(foreground)=white); Set(reply=("Set each factor equal to zero and solve for x."), reply(background)=red, reply(foreground)=white); Set(PLine=p0); end if; end proc: Showxs:=proc() global x1, x2, x3, der, dir, fact, fcn, p1, p0; Set(TFxs=sprintf("%a, %a, %a",x1, x2, x3)); Set(LInt1(caption)=sprintf("(-infinity,%a)",x1)); Set(LInt2(caption)=sprintf("(%a,%a)",x1,x2)); Set(LInt3(caption)=sprintf("(%a,%a)",x2,x3)); Set(LInt4(caption)=sprintf("(%a,infinity)",x3)); Set(Int1(caption)=sprintf("(-infinity,%a)",x1)); Set(Int2(caption)=sprintf("(%a,%a)",x1,x2)); Set(Int3(caption)=sprintf("(%a,%a)",x2,x3)); Set(Int4(caption)=sprintf("(%a,infinity)",x3)); Set(replyxs=("Shown"), replyxs(background)=yellow, replyxs(foreground)=black); Set(reply=("Next time try it on your own."), reply(background)=yellow, reply(foreground)=black); Set(PLine=p1); end proc: CheckInts:=proc() global x1, x2, x3, der, dir, fact, fcn, p0, p1, TestInt1, TestInt2, TestInt3, TestInt4; local user_Int1p, user_Int2p, user_Int3p, user_Int4p, user_Int1m,user_Int2m, user_Int3m, user_Int4m, ncorrect; ncorrect:=0; user_Int1p:=Get(RB1p::truefalse); user_Int2p:=Get(RB2p::truefalse); user_Int3p:=Get(RB3p::truefalse); user_Int4p:=Get(RB4p::truefalse); user_Int1m:=Get(RB1m::truefalse); user_Int2m:=Get(RB2m::truefalse); user_Int3m:=Get(RB3m::truefalse); user_Int4m:=Get(RB4m::truefalse); if (TestInt1>0 and user_Int1p) or (TestInt1<0 and user_Int1m) then ncorrect:=ncorrect+1; end if; if (TestInt2>0 and user_Int2p) or (TestInt2<0 and user_Int2m) then ncorrect:=ncorrect+1; end if; if (TestInt3>0 and user_Int3p) or (TestInt3<0 and user_Int3m) then ncorrect:=ncorrect+1; end if; if (TestInt4>0 and user_Int4p) or (TestInt4<0 and user_Int4m) then ncorrect:=ncorrect+1; end if; if ncorrect=4 then Set(replyInts=("Correct"), replyInts(background)=green, replyInts(foreground)=black); Set(reply=("Bazinga. One more step; keep going."), reply(background)=green, reply(foreground)=black); else Set(replyInts=("Incorrect"), replyInts(background)=red, replyInts(foreground)=white); Set(reply=sprintf("You have %a correct and %a wrong.", ncorrect, 4-ncorrect), reply(background)=red, reply(foreground)=white); end if; end proc: ShowInts:=proc() global x1, x2, x3, der, dir, fact, fcn, p0, p1, TestInt1, TestInt2, TestInt3, TestInt4; if TestInt1>0 then Set(RB1p=true); else Set(RB1m=true); end if; if TestInt2>0 then Set(RB2p=true); else Set(RB2m=true); end if; if TestInt3>0 then Set(RB3p=true); else Set(RB3m=true); end if; if TestInt4>0 then Set(RB4p=true); else Set(RB4m=true); end if; Set(replyInts="Shown", replyInts(background)=yellow, replyInts(foreground)=black); Set(reply="Next time try it on your own.", reply(background)=yellow, reply(foreground)=black); end proc: CheckAns:=proc() global x1, x2, x3, der, dir, fact, fcn, p0, p1, TestInt1, TestInt2, TestInt3, TestInt4; local user_Int1p, user_Ans1, user_Ans2, user_Ans3,user_Ans4,ncorrect; ncorrect:=0; user_Ans1:=Get(CBInt1::truefalse); user_Ans2:=Get(CBInt2::truefalse); user_Ans3:=Get(CBInt3::truefalse); user_Ans4:=Get(CBInt4::truefalse); if (TestInt1>0 and dir=1 and user_Ans1=true) or (TestInt1<0 and dir=2 and user_Ans1=true) or (TestInt1<0 and dir=1 and user_Ans1=false) or (TestInt1>0 and dir=2 and user_Ans1=false) then ncorrect:=ncorrect+1; end if; if (TestInt2>0 and dir=1 and user_Ans2=true) or (TestInt2<0 and dir=2 and user_Ans2=true) or (TestInt2<0 and dir=1 and user_Ans2=false) or (TestInt2>0 and dir=2 and user_Ans2=false) then ncorrect:=ncorrect+1; end if; if (TestInt3>0 and dir=1 and user_Ans3=true) or (TestInt3<0 and dir=2 and user_Ans3=true) or (TestInt3<0 and dir=1 and user_Ans3=false) or (TestInt3>0 and dir=2 and user_Ans3=false) then ncorrect:=ncorrect+1; end if; if (TestInt4>0 and dir=1 and user_Ans4=true) or (TestInt4<0 and dir=2 and user_Ans4=true) or (TestInt4<0 and dir=1 and user_Ans4=false) or (TestInt4>0 and dir=2 and user_Ans4=false) then ncorrect:=ncorrect+1; end if; if ncorrect=4 then Set(replyAns=("Correct"), replyAns(background)=green, replyAns(foreground)=black); Set(reply=("You are the calculus master! Try another one."), reply(background)=green, reply(foreground)=black); else Set(replyAns=("Incorrect"), replyAns(background)=red, replyAns(foreground)=white); Set(reply=sprintf("You have %a correct and %a wrong.", ncorrect, 4-ncorrect), reply(background)=red, reply(foreground)=white); end if; end proc: ShowAns:=proc() global x1, x2, x3, der, dir, fact, fcn, p0, p1, TestInt1, TestInt2, TestInt3, TestInt4; if dir=1 then if TestInt1>0 then Set(CBInt1=true); else Set(CBInt1=false); end if; if TestInt2>0 then Set(CBInt2=true); else Set(CBInt2=false); end if; if TestInt3>0 then Set(CBInt3=true); else Set(CBInt3=false); end if; if TestInt4>0 then Set(CBInt4=true); else Set(CBInt4=false); end if; else if TestInt1<0 then Set(CBInt1=true); else Set(CBInt1=false); end if; if TestInt2<0 then Set(CBInt2=true); else Set(CBInt2=false); end if; if TestInt3<0 then Set(CBInt3=true); else Set(CBInt3=false); end if; if TestInt4<0 then Set(CBInt4=true); else Set(CBInt4=false); end if; end if; Set(replyAns=("Shown"), replyAns(background)=yellow, replyAns(foreground)=black); Set(reply=("Next time try it on your own."), reply(background)=yellow, reply(foreground)=black); end proc: IncDec:=Maplet(onstartup = RunWindow(MAIN), Window[MAIN](title="Increasing or Decreasing Functions from the Sign of the Derivative", [ [ halign=none, Button("New Function", Evaluate(function="NewFunction"),background=magenta), HorizontalGlue(), [ halign=none, border=true, caption="Goal:", [ halign=none, Label[Lprob](sprintf("Find the intervals on which the following function is %s.","increasing")), HorizontalGlue() ], [ halign=none, "f(x) =", TextField[TFfunction](width=30, editable=false, background=white), HorizontalGlue() ] ], HorizontalGlue(), Button("Quit",Shutdown(),background=pink) ], [ halign=none, border=true, caption="Step 1: Find the derivative of the function:", "f '(x) =", TextField[TFder](width=20, background=turquoise), HorizontalGlue(), Button("Check",Evaluate(function="Checkder"),background=green), TextField[replyder](width=6, editable=false, background=white), Button("Show",Evaluate(function="Showder"),background=yellow) ], [ border=true, halign=none, caption="Step 2: Factor the derivative:", "f '(x) =", TextField[TFfact](width=30, background=turquoise), HorizontalGlue(), Button("Check",Evaluate(function="Checkfact"),background=green), TextField[replyfact](width=6, editable=false, background=white), Button("Show",Evaluate(function="Showfact"),background=yellow) ], BoxColumn( valign=none, inset=0, spacing=0, border=true, caption="Step 3: Find all the x's where f '(x)=0: (enter separated by commas)", [ halign=none, "x=", TextField[TFxs](width=30, background=turquoise), HorizontalGlue(), Button("Check",Evaluate(function="Checkxs"),background=green), TextField[replyxs](width=6, editable=false, background=white), Button("Show",Evaluate(function="Showxs"),background=yellow) ], [ halign=none, HorizontalGlue(), "The zeroes appear on this number line.", HorizontalGlue() ], [ halign=none, HorizontalGlue(), Plotter[PLine](width=400, height=50), HorizontalGlue() ] ), [ border=true, halign=none, caption="Step 4: Determine the sign of the derivative on each interval:", [ valign=none, inset=0, spacing=0, [ halign=none, RadioButton[RB1p]("+", group=BG1, background=turquoise), RadioButton[RB1m]("-", group=BG1, background=turquoise) ], Label[LInt1](sprintf("(-infinity,%a)",'a')) ], [ valign=none, inset=0, spacing=0, [ halign=none, 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, [ halign=none, RadioButton[RB3p]("+", group=BG3, background=turquoise), RadioButton[RB3m]("-", group=BG3, background=turquoise) ], Label[LInt3](sprintf("(%a,%a)",'b','c')) ], [ valign=none, inset=0, spacing=0, [ halign=none, RadioButton[RB4p]("+", group=BG4, background=turquoise), RadioButton[RB4m]("-", group=BG4, background=turquoise) ], Label[LInt4](sprintf("(%a,infinity)",'c')) ], HorizontalGlue(), Button("Check",Evaluate(function="CheckInts"),background=green), TextField[replyInts](width=6, editable=false, background=white), Button("Show",Evaluate(function="ShowInts"),background=yellow) ], [ halign=none, inset=0, border=true, caption="Step 5: Select the intervals where the function is", [ valign=none, inset=0, Label[Lstep5]("increasing:"), "", "", "" ], [ valign=none, inset=0, spacing=0, CheckBox[CBInt1](background=turquoise), Label[Int1](sprintf("(-infinity,%a)",'a')) ], [ valign=none, inset=0, spacing=0, CheckBox[CBInt2](background=turquoise), Label[Int2](sprintf(" (%a,%a) ",'a','b')) ], [ valign=none, inset=0, spacing=0, CheckBox[CBInt3](background=turquoise), Label[Int3](sprintf(" (%a,%a) ",'b','c')) ], [ valign=none, inset=0, spacing=0, CheckBox[CBInt4](background=turquoise), Label[Int4](sprintf("(%a,infinity)",'c')) ], HorizontalGlue(), Button("Check", Evaluate(function="CheckAns"), background=green), TextField[replyAns](width=6, editable=false, background=white), Button("Show", Evaluate(function="ShowAns"), background=yellow) ], [ TextBox[reply](width=40, height=2, editable=false, background=white) ], [ inset=0, spacing=0, "Instructor: Philip Yasskin", "Prorammers: Paige Petersen & Devon Hillman", "Copyright: Yasskin 2012" ] ] ), ButtonGroup[BG1](), ButtonGroup[BG2](), ButtonGroup[BG3](), ButtonGroup[BG4]() ): Maplets[Display](IncDec);