restart: with(Maplets): with(Maplets[Tools]): with(Maplets[Elements]): with(plots): StartEngine(); randomize(): MaxMinQuad:=Maplet(onstartup = RunWindow(MAIN), Window[MAIN]('title'="Max and Min of Quadratic Functions", [halign=none, [ "Identify the maximum or minimum of a quadratic function by completing the square.", HorizontalGlue(), Button("Quit", Shutdown()) ], [ Button("New Function", Evaluate('function' = "ask")), HorizontalGlue(), "f(x) =", TextField['func']('width'=20, 'editable'='false'), HorizontalGlue() ], [ "Complete the square by writing f in the form f(x) = a(x-p)^2 + q.", HorizontalGlue() ], [ "f(x) =", TextField['aval']('width'=3), "( x -", TextField['pval']('width'=3), ")^2 +", TextField['qval']('width'=3), HorizontalGlue(), Button("Hint", Evaluate('function' = "hint")), Button("Check", Evaluate('function' = "check")), Button("Show", Evaluate('function' = "show")) ], [ "This function has a", [ RadioButton[RBmax]("maximum", value=false, 'group'='BG1'), RadioButton[RBmin]("minimum", value=false, 'group'='BG1') ], "of f(x) =", TextField['qvalue']('width'=3), "at x =", TextField['pvalue']('width'=3), HorizontalGlue(), Button("Hint", Evaluate('function' = "hint2")), Button("Check", Evaluate('function' = "check2")), Button("Show", Evaluate('function' = "show2")) ], [ TextField['reply']('width'=40, 'editable'='false') ], ["Programmers: Fendley & Klemashevich Copyright P. Yasskin 2005" ] ] ), ButtonGroup['BG1']() ): rand5:=rand(-5..5): ask:=proc() global a,p,q, rand5; local b,c,f; a:=rand5(); while a=0 do a:=rand5() end do; p:=rand5(); q:=rand5(); b:=-2*a*p; c:=a*p^2+q; f:=a*x^2+b*x+c; Set('func'=f); Set('reply'=""); Set('aval'=""); Set('pval'=""); Set('qval'=""); Set(RBmax=false); Set(RBmin=false); Set('qvalue'=""); Set('pvalue'=""); end proc: check:=proc() global a,p,q; local useraval,userpval,userqval; useraval:=Get('aval'::'realcons'): userpval:=Get('pval'::'realcons'): userqval:=Get('qval'::'realcons'): if useraval=a and userpval=p and userqval=q then Set('reply'="Correct!"); return end if; if useraval<>a and userpval<>p and userqval<>q then Set('reply'="Incorrect. You have them all wrong. Try again."); return end if; if useraval<>a and userpval<>p and userqval=q then Set('reply'="Incorrect. You have the wrong values of a and p. Try again."); return end if; if useraval<>a and userpval=p and userqval<>q then Set('reply'="Incorrect. You have the wrong values of a and q. Try again."); return end if; if useraval=a and userpval<>p and userqval<>q then Set('reply'="Incorrect. You have the wrong values of p and q. Try again."); return end if; if useraval<>a then Set('reply'="Incorrect. You have the wrong value of a. Try again."); return end if; if userpval<>p then Set('reply'="Incorrect. You have the wrong value of p. Try again."); return end if; if userqval<>q then Set('reply'="Incorrect. You have the wrong value of q. Try again."); return end if; end proc: check2:=proc() global a,p,q; local usermax,usermin,userpvalue,userqvalue; usermax:=Get('RBmax'::'truefalse'): usermin:=Get('RBmin'::'truefalse'): userpvalue:=Get('pvalue'::'realcons'): userqvalue:=Get('qvalue'::'realcons'): if usermax=false and usermin=false then Set('reply'="You must first select maximum or minimum. Then check it again."); return end if; if a<0 then if usermax=true and userpvalue=p and userqvalue=q then Set('reply'="Correct"); return end if; if usermin=true and userpvalue=p and userqvalue=q then Set('reply'="Your max / min choice is wrong."); return end if; if usermax=true and userpvalue<>p and userqvalue=q then Set('reply'="Your x value is Incorrect"); return end if; if usermax=true and userpvalue=p and userqvalue<>q then Set('reply'="Your f(x) value is incorrect."); return end if; if usermax=true and userpvalue<>p and userqvalue<>q then Set('reply'="Both of your x and f(x) values are wrong."); return end if; if usermin=true and userpvalue<>p and userqvalue<>q then Set('reply'="You got it all wrong."); return end if; if usermin=true and userpvalue<>p and userqvalue=q then Set('reply'="Your x value is incorrect and your max / min choice was wrong."); return end if; if usermin=true and userpvalue=p and userqvalue<>q then Set('reply'="Your f(x) value is incorrect and your max / min choice was wrong."); return end if; end if; if a>0 then if usermin=true and userpvalue=p and userqvalue=q then Set('reply'="Correct"); return end if; if usermax=true and userpvalue=p and userqvalue=q then Set('reply'="Your max / min choice was wrong."); return end if; if usermin=true and userpvalue<>p and userqvalue=q then Set('reply'="Your x value is incorrect"); return end if; if usermin=true and userpvalue=p and userqvalue<>q then Set('reply'="Your f(x) value is incorrect."); return end if; if usermin=true and userpvalue<>p and userqvalue<>q then Set('reply'="Both of your x and f(x) values are wrong."); return end if; if usermax=true and userpvalue<>p and userqvalue<>q then Set('reply'="You got it all wrong."); return end if; if usermax=true and userpvalue<>p and userqvalue=q then Set('reply'="Your x value is incorrect and your max / min choice was wrong."); return end if; if usermax=true and userpvalue=p and userqvalue<>q then Set('reply'="Your f(x) value is incorrect and your max / min choice was wrong."); return end if; end if; end proc: show:=proc() global a,p,q; Set('aval'=a,'pval'=p,'qval'=q); end proc: show2:=proc() global a,p,q; if a<0 then Set(RBmax=true); end if; if a>0 then Set(RBmin=true); end if; Set('qvalue'=q,'pvalue'=p); end proc: hint:=proc() Set('reply'="If f = ax^2 + bx + c = a(x-p)^2 + q, then b = -2ap and c = ap^2+q."); end proc: hint2:=proc() Set('reply'="Maximum if a < 0; Minimum if a > 0."); end proc: Display(MaxMinQuad);