restart: with(Maplets[Tools]): with(Maplets[Elements]): with(plots): StartEngine(); randomize(): fs:=[u^2, 4*u^3, ln(u), exp(u), sin(u), cos(u), u^4/4]; randfs:=rand(1..nops(fs)): gs:=[x+1, x^2-3, x^3+2*x^2, 7*x, sin(x), cos(x)]; randgs:=rand(1..nops(gs)): new_function:=proc() global fs, gs, randfs, randgs, f, g, Df, Dg, Dfg, Dfog; f:=fs[randfs()]; g:=gs[randgs()]; Df:=diff(f,u); Dg:=diff(g,x); Dfg:=subs(u=g,Df); Dfog:=Dfg*Dg; Set('f_g_xMML'=MathML[Export](eval(f,u=g))); Set(f_u=""); Set(g_x=""); Set(dfu=""); Set(dgx=""); Set(dfgx=""); Set(df_o_g=""); Set(reply="", reply(background)=white); end proc: check_fu:=proc() global f; local user_f; user_f:=Get('f_u'::anything); if f-user_f=0 then Set(reply="That's the correct f(u). You're awesome! Try another one.", reply(background)=green); else Set(reply="f(u) is incorrect. f(u) is the outer function. Please try again.", reply(background)=red); end if end proc: show_fu:=proc() global f; Set('f_u'=f); Set(reply="", reply(background)=white); end proc: check_ugx:=proc() global g; local user_g; user_g:=Get('g_x'::anything); if g-user_g=0 then Set(reply="That's the correct g(x). You're awesome! Try another one.", reply(background)=green); else Set(reply="g(x) is incorrect. g(x) is the inner function. Please try again.", reply(background)=red); end if end proc: show_ugx:=proc() global g; Set('g_x'=g); Set(reply="", reply(background)=white); end proc: check_dfu:=proc() global Df; local user_Df; user_Df:=Get('dfu'::anything); if Df-user_Df=0 then Set(reply="Correct derivative of f(u). You're awesome! Try another one.", reply(background)=green); else Set(reply="The derivative of f(u) is incorrect. Please try again.", reply(background)=red); end if end proc: show_dfu:=proc() global Df; Set('dfu'=Df); Set(reply="", reply(background)=white); end proc: check_dgx:=proc() global Dg; local user_Dg; user_Dg:=Get('dgx'::anything); if Dg-user_Dg=0 then Set(reply="Correct derivative of g(x). You're awesome! Try another one.", reply(background)=green); else Set(reply="The derivative of g(x) is incorrect. Please try again.", reply(background)=red); end if end proc: show_dgx:=proc() global Dg; Set('dgx'=Dg); Set(reply="", reply(background)=white); end proc: check_dfgx:=proc() global Dfg; local user_Dfg; user_Dfg:=Get('dfgx'::anything); if Dfg-user_Dfg=0 then Set(reply="f '(g(x)) is correct. You're awesome! Try another one.", reply(background)=green); else Set(reply="f '(g(x)) is incorrect. Just replace u by g(x) in f '(u). Please try again.", reply(background)=red); end if end proc: show_dfgx:=proc() global Dfg; Set('dfgx'=Dfg); Set(reply="", reply(background)=white); end proc: check_Dfog:=proc() global Dfog; local user_Dfog; user_Dfog:=Get('df_o_g'::anything); if Dfog-user_Dfog=0 then Set(reply="The final answer is correct. You really got it together! Try another function.", reply(background)=green); else Set(reply="The answer is incorrect. Simply multiply f '(g(x)) by g '(x). Please try again.", reply(background)=red); end if end proc: show_Dfog:=proc() global Dfog; Set('df_o_g'=Dfog); Set(reply="", reply(background)=white); end proc: Preview:=proc(TFname) local expr; global CurrentTFname; options `Copyright 2005, Philip B. Yasskin, Texas A&M Univ., and Douglas B. Meade, Univ of South Carolina`; CurrentTFname := TFname; if Get(TFname)="" then Set('reply'="You must enter an expression to be previewed.", 'reply'(background)=orange, reply(foreground)=black); else expr:=Get(TFname::anything, corrections=true, update=true); Set('TFPreview' = expr); Set('MMLPreview' = MathML[Export](expr)); Set('ARunPreview'(run)=true); end if; end proc: Update_Preview:=proc() local expr; global CurrentTFname; options `Copyright 2005, Philip B. Yasskin, Texas A&M Univ., and Douglas B. Meade, Univ of South Carolina`; expr:=Get(TFPreview::anything, corrections=true); Set('MMLPreview' = MathML[Export](expr)); Set(CurrentTFname = expr); end proc: Chain_Rule:= Maplet(onstartup = RunWindow(MAIN), Font[helv10]("helvetica",10), Window[MAIN]('title'="Chain Rule", [ halign=none, background=black, [ Button("New Function", Evaluate('function' = "new_function"),background=turquoise), "f(g(x))=", MathMLViewer[f_g_xMML]('value' = MathML[Export](""), width=150, height=75), Button("Quit", Shutdown(),background=white) ], [ "f(u) = ", TextField['f_u']('width'=10),background=turquoise, HorizontalGlue(), Button[Bf_u_pr]("Preview", onclick=APreview_f_u), Button("Check", Evaluate('function' = "check_fu")), Button("Show", Evaluate('function' = "show_fu")) ], [ "u=g(x) =", TextField['g_x']('width'=10), HorizontalGlue(), Button[Bfugpr]("Preview", onclick=APreview_g_x, background=turquoise), Button("Check", Evaluate('function' = "check_ugx"),background=turquoise), Button("Show", Evaluate('function' = "show_ugx"),background=turquoise) ], [ "f '(u) = ", TextField['dfu']('width'=10),background=turquoise, HorizontalGlue(), Button[Bdfupr]("Preview", onclick=APreview_dfu), Button("Check", Evaluate('function' = "check_dfu")), Button("Show", Evaluate('function' = "show_dfu")) ], [ "g '(x) = ", TextField['dgx']('width'=10), HorizontalGlue(), Button[Bdgxpr]("Preview", onclick=APreview_dgx, background=turquoise), Button("Check", Evaluate('function' = "check_dgx"),background=turquoise), Button("Show", Evaluate('function' = "show_dgx"),background=turquoise) ], [ "f '(g(x)) =", TextField['dfgx']('width'=10),background=turquoise, HorizontalGlue(), Button[Bdfgxpr]("Preview", onclick=APreview_dfgx), Button("Check", Evaluate('function' = "check_dfgx")), Button("Show", Evaluate('function' = "show_dfgx")) ], [ "(fog)'(x) = f '(g(x)) g '(x) =", TextField['df_o_g']('width'=10), HorizontalGlue(), Button[BDfogpr]("Preview", onclick=APreview_Dfog, background=turquoise), Button("Check", Evaluate('function' = "check_Dfog"),background=turquoise), Button("Show", Evaluate('function' = "show_Dfog"),background=turquoise) ], [ background=turquoise, TextField[reply]("", background=white, 'width'=50) ], BoxRow('background'="#DDFFFF", 'inset'=0, 'spacing'=0, Label("Programmers: Neil Matula / Kim Dulock ", 'font'=helv10), HorizontalGlue(), Label("Copyright 2006, D.B. Meade and P.B. Yasskin ", 'font'=helv10), HorizontalGlue(), Label("v. 1.2a May 2006", 'font'=helv10) ) ] ), Window[PREVIEW]( 'title'="Preview", 'defaultbutton'='UpdatePreview', [ halign=none, background=wheat, [ background=wheat, TextField['TFPreview']('width'=50, background=turquoise), Button['UpdatePreview']("Update", Evaluate('function' = "Update_Preview()"), background=turquoise), Button['ClosePreview']("Close", CloseWindow(PREVIEW), background=white) ], [ background=wheat, MathMLViewer[MMLPreview]('value'=MathML[Export](Int(f(x),x)), 'width'=500, 'height'=100) ] ]), Action[ARunPreview](RunWindow(PREVIEW)), Action[APreview_f_u](Evaluate('function' = "Preview(f_u)")), Action[APreview_g_x](Evaluate('function' = "Preview(g_x)")), Action[APreview_dfu](Evaluate('function' = "Preview(dfu)")), Action[APreview_dgx](Evaluate('function' = "Preview(dgx)")), Action[APreview_dfgx](Evaluate('function' = "Preview(dfgx)")), Action[APreview_Dfog](simplify(Evaluate('function' = "Preview(df_o_g)"))) ): Maplets[Display](Chain_Rule);