restart: with(Maplets[Elements]):with(Maplets[Tools]): StartEngine(); randomize(): great := [ " Correct. ", " YES! ", " Perfect. ", " Awesome! ", " Excellent! ", " Way to GO!", " Now that's how you do it!", " I couldn't have done it better! ", " Ding Ding Ding, we have a winner. " ]: randgreat := rand(1..nops(great)): nextquest := [ "Try another one.", "Give it another shot.", "Can you do that again?", "Approximate another point." ]: randnext := rand(1..nops(nextquest)): sorry := [ " Not really what I was looking for. ", " Nope. ", " Sorry, That's incorrect. ", " Ooooh...so close. ", " Oops. ", " Wrong Wrong Wrong. You have it all WRONG. " ]: randsorry := rand(1..nops(sorry)): tryagain := [ "Try the hint.", "Guess again.", "They say the third times the charm. Please try again.", "Try again.", "Please try again." ]: randtry := rand(1..nops(tryagain)): showit := [ " OK now try it yourself.", " I know how you work- you click SHOW IT so I have to do all the work! How about you try it yourself!?", " Now try using your own mind for a change to solve the problem.", " Do you see how it's done now? Okay now you try it.", " That was practice. Now it's your turn." ]: randshow := rand(1..nops(showit)): i:=0: i:=i+1: funcs[i]:=1/x: i:=i+1: funcs[i]:=x^2: i:=i+1: funcs[i]:=1/x^2: i:=i+1: funcs[i]:=x^2+3*x+5: i:=i+1: funcs[i]:=x+x^2/3: i:=i+1: funcs[i]:=x^3-2*x+5: i:=i+1: funcs[i]:=4*x-x^3: i:=i+1: funcs[i]:=7*x-x^2+2/4: i:='i': randfunc := rand(1..8): Show_Function := proc() local p1; global randfunc, whichfunc, funcs, func, A, randpt, As, randpts, whichpoint, x, a, funca, funcp, funcpa, functan, functana; whichfunc := randfunc(); func := funcs[whichfunc]; funca := eval(func, x=2); funcp := diff(func,x); funcpa := simplify(eval(funcp, x=2)); functan := funca + funcpa * (x-2); functana := funca + funcpa * (2.1-2); Set('fMML' = func): Set('fa' = ""): Set('fp' = ""): Set('fpa' = ""): Set('ftan' = ""): Set('ftana' =""): Set('fack' = "", 'fack'(background)=white, 'fack'(foreground) = black): Set('fpck' = "", 'fpck'(background)=white, 'fpck'(foreground) = black): Set('fpack' = "", 'fpack'(background)=white, 'fpack'(foreground) = black): Set('ftanck' = "", 'ftanck'(background)=white, 'ftanck'(foreground) = black): Set('ftanack' = "", 'ftanack'(background)=white, 'ftanack'(foreground) = black): Set('reply' = "", 'reply'(background)=white, 'reply'(foreground) = black): Set('Bfack'(enabled)=true, 'Bfack'(background)=turquoise); Set('Bfash'(enabled)=true, 'Bfash'(background)=turquoise); Set('Bfpck'(enabled)=true, 'Bfpck'(background)=turquoise); Set('Bfpsh'(enabled)=true, 'Bfpsh'(background)=turquoise); Set('Bfpack'(enabled)=true, 'Bfpack'(background)=turquoise); Set('Bfpash'(enabled)=true, 'Bfpash'(background)=turquoise); Set('Bftanck'(enabled)=true, 'Bftanck'(background)=turquoise); Set('Bftanack'(enabled)=true, 'Bftanack'(background)=turquoise); Set('Bftanash'(enabled)=true, 'Bftanash'(background)=turquoise); Set('Bftansh'(enabled)=true, 'Bftansh'(background)=turquoise); end proc: Check_fa := proc() local user_fa; global funca, x; user_fa := Get('fa'::algebraic, corrections=true, update=true): if simplify(normal(funca - user_fa))<> 0 then Set('fack' = "incorrect", 'fack'(background)=red, 'fack'(foreground) = white): Set('reply' = cat(sorry[randsorry()], tryagain[randtry()]), 'reply'(background)=red, 'reply'(foreground) = white): else Set('fack' = " correct ", 'fack'(background)=green, 'fack'(foreground) = black): Set('reply' = cat(great[randgreat()]), 'reply'(background)=green, 'reply'(foreground) = black): end if; end proc: Show_fa := proc() global funca, x; Set('fa' = funca): Set('fack' = " ", 'fack'(background)=white, 'fack'(foreground) = black): Set('reply' = showit[randshow()], 'reply'(background)=turquoise, 'reply'(foreground) = black): end proc: Check_fp := proc() local user_fp; global funcp, x; user_fp := Get('fp'::algebraic, corrections=true, update=true): if simplify(normal(funcp - user_fp))<> 0 then Set('fpck' = "incorrect", 'fpck'(background)=red, 'fpck'(foreground) = white): Set('reply' = cat(sorry[randsorry()], tryagain[randtry()]), 'reply'(background)=red, 'reply'(foreground) = white): else Set('fpck' = " correct ", 'fpck'(background)=green, 'fpck'(foreground) = black): Set('reply' = cat(great[randgreat()]), 'reply'(background)=green, 'reply'(foreground) = black): end if; end proc: Show_fp := proc() global funcp, x; Set('fp' = funcp): Set('fpck' = " ", 'fpck'(background)=white, 'fpck'(foreground) = black): Set('reply' = showit[randshow()], 'reply'(background)=turquoise, 'reply'(foreground) = black): end proc: Check_fpa := proc() local user_fpa; global funcpa, x; user_fpa := Get('fpa'::algebraic, corrections=true, update=true): if simplify(normal(funcpa - user_fpa))<> 0 then Set('fpack' = "incorrect", 'fpack'(background)=red, 'fpack'(foreground) = white): Set('reply' = cat(sorry[randsorry()], tryagain[randtry()]), 'reply'(background)=red, 'reply'(foreground) = white): else Set('fpack' = " correct ", 'fpack'(background)=green, 'fpack'(foreground) = black): Set('reply' = cat(great[randgreat()]), 'reply'(background)=green, 'reply'(foreground) = black): end if; end proc: Show_fpa := proc() global funcpa, x; Set('fpa' = funcpa): Set('fpack' = " ", 'fpack'(background)=white, 'fpack'(foreground) = black): Set('reply' = showit[randshow()], 'reply'(background)=turquoise, 'reply'(foreground) = black): end proc: Check_ftan := proc() local user_ftan; global functan, x; user_ftan := Get('ftan'::algebraic, corrections=true, update=true): if simplify(normal(functan - user_ftan))<> 0 then Set('ftanck' = "incorrect", 'ftanck'(background)=red, 'ftanck'(foreground) = white): Set('reply' = cat(sorry[randsorry()], tryagain[randtry()]), 'reply'(background)=red, 'reply'(foreground) = white): else Set('ftanck' = " correct ", 'ftanck'(background)=green, 'ftanck'(foreground) = black): Set('reply' = cat(great[randgreat()]), 'reply'(background)=green, 'reply'(foreground) = black): end if; end proc: Show_ftan := proc() global funcpa, x; Set('ftan' = functan): Set('ftanck' = " ", 'ftanck'(background)=white, 'ftanck'(foreground) = black): Set('reply' = showit[randshow()], 'reply'(background)=turquoise, 'reply'(foreground) = black): end proc: Check_ftana := proc() local user_ftana; global functana, x; user_ftana := Get('ftana'::algebraic, corrections=true, update=true): if simplify(normal(functana - user_ftana))<> 0 then Set('ftanack' = "incorrect", 'ftanack'(background)=red, 'ftanack'(foreground) = white): Set('reply' = cat(sorry[randsorry()], tryagain[randtry()]), 'reply'(background)=red, 'reply'(foreground) = white): else Set('ftanack' = " correct ", 'ftanack'(background)=green, 'ftanack'(foreground) = black): Set('reply' = cat(great[randgreat()], nextquest[randnext()]), 'reply'(background)=green, 'reply'(foreground) = black): end if; end proc: Show_ftana := proc() global funcpa, x; Set('ftana' = functana): Set('ftanack' = " ", 'ftanack'(background)=white, 'ftanack'(foreground) = black): Set('reply' = showit[randshow()], 'reply'(background)=turquoise, 'reply'(foreground) = black): end proc: Hint := proc() global a; Set('reply' = cat("Use the function L(x) = f(a) + f'(a) (x-a) to compute the linear approximation."), 'reply'(background)=turquoise, 'reply'(foreground) = black): end proc: LinearApproximation := Maplet(onstartup = RunWindow(MAIN), Font[helv10]("helvetica",10), Window[MAIN]( 'title'="Finding Linear Approximations", 'defaultbutton'='BHint', [ halign=none, background=wheat, [ background=wheat, Button['Bnew']("New Function", Evaluate('function' = "Show_Function"), background=turquoise), HorizontalGlue(), Button['BHint']("Hint", Evaluate('function' = "Hint"), background=turquoise), Button("Quit", Shutdown(), background=turquoise) ], BoxColumn( halign=none, border=true, inset=0, background=wheat, caption = "Goal:", [background=wheat, "Find the linear approximation of f (x) =", MathMLViewer[fMML]('value'=MathML[Export](" "), 'width'=100, 'height'=60), "at the point x = 2", HorizontalGlue() ], [background=wheat, "Use it to approximate f (2.1).", HorizontalGlue() ] ), BoxColumn( halign=none, border=true, inset=0, background=wheat, caption = "Let's see what you can do:", [ background=wheat, " f(2) = ", TextField['fa']('width'=20, 'background'=pink), HorizontalGlue(), Button['Bfack']("Check", Evaluate('function' = "Check_fa"), background=wheat, enabled=false), TextField['fack']('width'=6, editable=false, background=white), Button['Bfash']("Show", Evaluate('function' = "Show_fa"), background=wheat, enabled=false) ], [ background=wheat, " f '(x) = ", TextField['fp']('width'=20, 'background'=pink), HorizontalGlue(), Button['Bfpck']("Check", Evaluate('function' = "Check_fp"), background=wheat, enabled=false), TextField['fpck']('width'=6, editable=false, background=white), Button['Bfpsh']("Show", Evaluate('function' = "Show_fp"), background=wheat, enabled=false) ], [ background=wheat, " f '(2) = ", TextField['fpa']('width'=20, 'background'=pink), HorizontalGlue(), Button['Bfpack']("Check", Evaluate('function' = "Check_fpa"), background=wheat, enabled=false), TextField['fpack']('width'=6, editable=false, background=white), Button['Bfpash']("Show", Evaluate('function' = "Show_fpa"), background=wheat, enabled=false) ], [ background=wheat, " L(x) = ", TextField['ftan']('width'=20, 'background'=pink), HorizontalGlue(), Button['Bftanck']("Check", Evaluate('function' = "Check_ftan"), background=wheat, enabled=false), TextField['ftanck']('width'=6, editable=false, background=white), Button['Bftansh']("Show", Evaluate('function' = "Show_ftan"), background=wheat, enabled=false) ] ), BoxRow( border=true, inset=0, background=wheat, caption = "Approximate:", " f(2.1) ~", TextField['ftana']('width'=26, 'background'=pink), HorizontalGlue(), Button['Bftanack']("Check", Evaluate('function' = "Check_ftana"), background=wheat, enabled=false), TextField['ftanack']('width'=6, editable=false, background=white), Button['Bftanash']("Show", Evaluate('function' = "Show_ftana"), background=wheat, enabled=false), "" ), TextBox['reply']('width'=70, 'height'=2, 'editable'='false', background=white ), BoxRow('background'=pink, 'inset'=0, 'spacing'=0, Label("Copyright November 2005", 'font'=helv10), HorizontalGlue(), Label("Project By:Jessica Bailey", 'font'=helv10), HorizontalGlue(), Label("Yasskin Math151-202", 'font'=helv10) ) ]), ButtonGroup['BG1']() ): Maplets[Display]( LinearApproximation );