restart: with(Maplets): with(Maplets[Tools]): with(Maplets[Elements]): with(plots): StartEngine(); randomize(): DomainFinder:=Maplet(onstartup = RunWindow(MAIN), Window[MAIN]('title'="Domain Finder for Square Root Functions", [ halign=none, [ Button("New Function", Evaluate('function' = "ask")), HorizontalGlue(), Button("Quit", Shutdown()) ], [ "What is the domain of the following function?", HorizontalGlue() ], [ MathMLViewer['function']('width'=300,'height'=60 ) ], [ HorizontalGlue(), [ RadioButton['RBleftparen']("(", 'value'=false, 'group'='BGleft'), RadioButton['RBleftbrack']("[", 'value'=false, 'group'='BGleft') ], TextField['intervalleft']('width'=15), ",", TextField['intervalright']('width'=15), [ RadioButton['RBrightparen'](")", 'value'=false, 'group'='BGright'), RadioButton['RBrightbrack']("]", 'value'=false, 'group'='BGright') ], HorizontalGlue() ], [ HorizontalGlue(), Button("Check Answer", Evaluate('function' = "check")), HorizontalGlue(), Button("Show Answer", Evaluate('function'="show")), Button("Plot It", onclick=A1), HorizontalGlue() ], [ "Comment:",TextBox['reply']('width'=60, height=2, 'editable'='false') ], ["Programmers: Hammer & Peters Copyright P. Yasskin 2005" ] ] ), Window[PlotIt]('title'="The Plot", [ Plotter['myplot'](plot(0, x=-10..10, y=0..5),'width'=300, 'height'=300), Button("Good Bye", CloseWindow(PlotIt)) ] ), Action[A1](RunWindow(PlotIt), Evaluate('function' = "plotfunc")), ButtonGroup['BGleft'](), ButtonGroup['BGright']() ): First:=true: vrange:=0..5: card:=rand(0..1): rand8:=rand(1..8): rand3:=rand(1..3): ask:=proc() local a,b,funcs; global card,rand8,rand3,n, leftb, rightb, intleft, intright, f,x, vrange, First; a:=(-1)^card()*rand8(); b:=(-1)^card()*rand8(); Set('reply'=""); Set('RBleftparen'=false); Set('RBleftbrack'=false); Set('RBrightparen'=false); Set('RBleftbrack'=false); Set('intervalleft'=""); Set('intervalright'=""); if not First then Set('myplot'=plot(0, x=-10..10, y=0..5)) end if; funcs:=[sqrt(a*x+b),1/sqrt(a*x+b),sqrt(a/(x-b))]; n:=rand3(); f:=funcs[n]; Set('function'=MathML[Export]('f(x)'=f)); if a>0 and n=1 then leftb:=0; rightb:=1; intleft:=-b/a; intright:=infinity; vrange:=0..5 end if; if a<0 and n=1 then leftb:=1; rightb:=0; intleft:=-infinity; intright:=-b/a; vrange:=0..5 end if; if a>0 and n=2 then leftb:=1; rightb:=1; intleft:=-b/a; intright:=infinity; vrange:=0..5 end if; if a<0 and n=2 then leftb:=1; rightb:=1; intleft:=-infinity; intright:= b/a; vrange:=0..5 end if; if a>0 and n=3 then leftb:=1; rightb:=1; intleft:=b; intright:= infinity; vrange:=0..5 end if; if a<0 and n=3 then leftb:=1; rightb:=1; intleft:=-infinity; intright:= b; vrange:=0..5 end if; end proc: check:=proc() global leftb, rightb, intleft, intright; local userleftparen, userleftbrack, userintervalleft, userintervalright, userrightparen, userrightbrack, userleftb, userrightb; userleftparen:=Get('RBleftparen'::truefalse); userleftbrack:=Get('RBleftbrack'::truefalse); userintervalleft:=Get('intervalleft'::anything, corrections=true, update=true); userintervalright:=Get('intervalright'::anything, corrections=true, update=true); userrightparen:=Get('RBrightparen'::truefalse); userrightbrack:=Get('RBrightbrack'::truefalse); if (not userleftparen and not userleftbrack) or (not userrightparen and not userrightbrack) then Set('reply'="You must select a left and right parenthesis or bracket. Then check again."); return end if; if userleftparen then userleftb:=1 else userleftb:=0 end if; if userrightparen then userrightb:=1 else userrightb:=0 end if; if userleftb-leftb=0 and userrightb-rightb=0 and userintervalleft=intleft and userintervalright=intright then Set('reply'="Correct! Good Job!") elif not userleftb-leftb=0 or not userrightb-rightb=0 then Set('reply'="Incorrect. Check your parentheses and brackets.") else Set('reply'="Incorrect. Check your endpoints.") end if; end proc: show:=proc() global leftb, rightb, intleft, intright; Set('intervalleft'=intleft); Set('intervalright'=intright); if leftb=0 then Set(RBleftbrack=true) else Set(RBleftparen=true) end if; if rightb=0 then Set(RBrightbrack=true) else Set(RBrightparen=true) end if; end proc: plotfunc:=proc() local p1; global f, vrange, First; First:=false; p1:=plot(f, x=-10..10, y=vrange); Set('myplot'=p1) end proc: Display(DomainFinder);