Nicole Wanlass
Finding and Classifying Critical Pointsrestart;with(Maplets[Tools]): with(Maplets[Elements]): with(RandomTools):
StartEngine();randomize():lightorange:="#FFB300":
lightcyan:="#DDFFFF":ColorFooter:=lightcyan:
FontFooter:=Font("helvetica",10):rand10:=rand(-10...10):randcube:=rand(0...1):randc:=rand(1...10):newfunction:=proc()
global x1,x2,cube,fp,fpp,fpp0,fpp1,fpp2;
local c,c1,d,f;
x1:=rand10();
x2:=rand10();
c:=randc();
c1:=Generate(choose({-1,1})):
d:=rand10();
cube:=randcube();
fp:=sort(expand(x^cube*c*c1*(x-x1)*(x-x2)));
f:=int(fp,x)+d;
if rand10=sprintf("%a",0) then
Evaluate(function="newfunction");
else
Set(ML1=f);
fpp:=diff(fp,x);
fpp0:=eval(fpp,x=0);
fpp1:=eval(fpp,x=x1);
fpp2:=eval(fpp,x=x2);
Set(TFfp="");
Set(TFfpp="");
Set(TFxs="");
Set(TFppa="");
Set(TFppa2="");
Set(TFa="");
Set(Radio1=false);
Set(Radio2=false);
Set(Radio3=false);
Set(reply="");
end if;
end proc:Checkfp:=proc()
global x1,x2,cube,fp,fpp,fpp0,fpp1,fpp2;
local userfp, userfp2;
userfp:=Get(TFfp::polynom);
userfp2:=Get(TFfp);
if userfp=fp then
Set(reply="Awesome job! That's the correct derivative.");
else
Set(reply="Sorry. That's not the derivative.");
end if;
end proc:Showfp:=proc()
global x1,x2,cube,fp,fpp,fpp0,fpp1,fpp2;
Set(TFfp=fp);
Set(reply="Try to do it yourself next time.");
end proc:Checkfpp:=proc()
global x1,x2,cube,fp,fpp,fpp0,fpp1,fpp2;
local userfpp;
userfpp:=Get(TFfpp::polynom);
if userfpp=fpp then
Set(reply="Perfect! That's the correct second derivative.");
else
Set(reply="Sorry. That's not the correct second derivative.")
end if;
end proc:Showfpp:=proc()
global x1,x2,cube,fp,fpp,fpp0,fpp1,fpp2;
Set(TFfpp=fpp);
Set(reply="Try to do it yourself next time.");
end proc:Checkxs:=proc()
global x1,x2,cube,fp,fpp,fpp0,fpp1,fpp2;
local userxs;
userxs:=Get(TFxs);
if userxs=sprintf("%a,%a",x1,x2) and cube=0 or
userxs=sprintf("%a,%a",x2,x1) and cube=0 or
userxs=sprintf("%a,%a,%a",0,x1,x2) and cube=1 or
userxs=sprintf("%a,%a,%a",0,x2,x1) and cube=1 or
userxs=sprintf("%a,%a,%a",x1,0,x2) and cube=1 or
userxs=sprintf("%a,%a,%a",x1,x2,0) and cube=1 or
userxs=sprintf("%a,%a,%a",x2,0,x1) and cube=1 or
userxs=sprintf("%a,%a,%a",x2,x1,0) and cube=1 then
Set(reply="You've got it! Those are the correct x's.");
else
Set(reply="Sorry. Those aren't the correct x's.")
end if;
end proc:Showxs:=proc()
global x1,x2,cube,fp,fpp,fpp0,fpp1,fpp2;
local pxs;
if cube=0 then
pxs:=sprintf("%a,%a",x1,x2);
Set(TFxs=pxs);
else
pxs:=sprintf("%a,%a,%a",x1,x2,0);
Set(TFxs=pxs);
Set(reply="Try to do it yourself next time.")
end if
end proc:Critical1:=proc()
global x1,x2,cube,fp,fpp,fpp0,fpp1,fpp2;
Set(TFppa=x1);
Set(TFa=x1);
Set(TFppa2="");
Set(Radio1=false);
Set(Radio2=false);
Set(Radio3=false);
Set(reply="");
end proc:Critical2:=proc()
global x1,x2,cube,fp,fpp,fpp0,fpp1,fpp2;
Set(TFppa=x2);
Set(TFa=x2);
Set(TFppa2="");
Set(Radio1=false);
Set(Radio2=false);
Set(Radio3=false);
Set(reply="");
end proc:Critical3:=proc()
global x1,x2,cube,fp,fpp,fpp0,fpp1,fpp2;
if cube=1 then
Set(TFppa=0);
Set(TFa=0);
Set(TFppa2="");
Set(reply="");
else
Set(TFppa="---");
Set(TFa="---");
Set(TFppa2="---");
Set(reply="There is no third critical point for this function.");
end if;
Set(Radio1=false);
Set(Radio2=false);
Set(Radio3=false);
end proc:Checkfppa:=proc()
global x1,x2,cube,fp,fpp,fpp0,fpp1,fpp2,TFppaget;
local userppa;
TFppaget:=Get(TFppa);
userppa:=Get(TFppa2);
if TFppaget=sprintf("%a",x1) and userppa=sprintf("%a",fpp1) then
Set(reply="Great! That's the correct evaluation.");
elif TFppaget=sprintf("%a",x2) and userppa=sprintf("%a",fpp2) then
Set(reply="Fabulous! That's the correct evaluation.");
elif TFppaget=sprintf("%a",0) and userppa=sprintf("%a",fpp0) then
Set(reply="Fantastic! That's the correct evaluation.");
else
Set(reply="Sorry. That's not the correct evaluation.");
end if;
end proc:Showfppa:=proc()
global x1,x2,cube,fp,fpp,fpp0,fpp1,fpp2;
local TFppaget;
TFppaget:=Get(TFppa);
if TFppaget=sprintf("%a",x1) then
Set(TFppa2=fpp1);
elif TFppaget=sprintf("%a",x2) then
Set(TFppa2=fpp2);
elif TFppaget=sprintf("%a",0) then
Set(TFppa2=fpp0);
end if;
Set(reply="Try to do it yourself next time.");
end proc:CheckClass:=proc()
global x1,x2,cube,fp,fpp,fpp0,fpp1,fpp2;
local TFppaget;
TFppaget:=Get(TFppa);
if Get(Radio1)=true and TFppaget=sprintf("%a",x1) and fpp1>0 or
Get(Radio2)=true and TFppaget=sprintf("%a",x1) and fpp1<0 or
Get(Radio3)=true and TFppaget=sprintf("%a",x1) and fpp1=0 then
Set(reply="There you have it! That's the correct classification. Now try the next critical point.");
elif Get(Radio1)=true and TFppaget=sprintf("%a",x2) and fpp2>0 and cube=1 or
Get(Radio2)=true and TFppaget=sprintf("%a",x2) and fpp2<0 and cube=1 or
Get(Radio3)=true and TFppaget=sprintf("%a",x3) and fpp2=0 and cube=1 then
Set(reply="Yes! That's the correct classification. Onto the next critical point.");
elif Get(Radio1)=true and TFppaget=sprintf("%a",x2) and fpp2>0 and cube=0 or
Get(Radio2)=true and TFppaget=sprintf("%a",x2) and fpp2<0 and cube=0 or
Get(Radio3)=true and TFppaget=sprintf("%a",x3) and fpp2=0 and cube=0 then
Set(reply="Yes! That's the correct classification. Now try another problem.");
elif Get(Radio1)=true and TFppaget=sprintf("%a",0) and fpp0>0 or
Get(Radio2)=true and TFppaget=sprintf("%a",0) and fpp0<0 or
Get(Radio3)=true and TFppaget=sprintf("%a",0) and fpp0=0 then
Set(reply="Wonderful! That's the correct classification. Now try another problem.");
else
Set(reply="Sorry. That's not the correct classification.");
end if;
end proc:ShowClass:=proc()
global x1,x2,cube,fp,fpp,fpp0,fpp1,fpp2;
local TFppaget;
TFppaget:=Get(TFppa);
if TFppaget=sprintf("%a",x1) and fpp1>0 or
TFppaget=sprintf("%a",x2) and fpp2>0 or
TFppaget=sprintf("%a",0) and fpp0>0 then
Set(Radio1=true);
elif TFppaget=sprintf("%a",x1) and fpp1<0 or
TFppaget=sprintf("%a",x2) and fpp2<0 or
TFppaget=sprintf("%a",0) and fpp0<0 then
Set(Radio2=true);
elif TFppaget=sprintf("%a",x1) and fpp1=0 or
TFppaget=sprintf("%a",x2) and fpp2=0 or
TFppaget=sprintf("%a",0) and fpp0=0 then
Set(Radio3=true);
end if;
Set(reply="Try to do it yourself next time.");
end proc:CriticalPoints:= Maplet(onstartup=RunWindow(MAIN),
Window[MAIN](title="Finding and Classifying Critical Points",
[
[ halign=none,
Button("New Function",Evaluate(function="newfunction"),background=cyan),
HorizontalGlue(),
Label("f(x) = ",font=Font(family=Helvetica,size=16)),
MathMLViewer[ML1](width=200, height=60),
HorizontalGlue(),
Button("Quit",Shutdown(),background=pink)
],
[ halign=none,border=true,caption="Step 1: Find f ' (x).",
Label("f ' (x) = ",font=Font(family=Helvetica,size=16)),
TextField[TFfp](width=40,editable=true),
HorizontalGlue(),
Button("Check",Evaluate(function="Checkfp"),background=green),
Button("Show",Evaluate(function="Showfp"),background=yellow)
],
[ halign=none,border=true,caption="Step 2: Find f '' (x).",
Label("f '' (x) = ",font=Font(family=Helvetica,size=16)),
TextField[TFfpp](width=40,editable=true),
HorizontalGlue(),
Button("Check",Evaluate(function="Checkfpp"),background=green),
Button("Show",Evaluate(function="Showfpp"),background=yellow)
],
[ halign=none,border=true,caption="Step 3: Set f ' (x) = 0 and solve for the x's. Separate answers with commas.",
Label("x = ",font=Font(family=Helvetica,size=16)),
TextField[TFxs](width=40,editable=true),
HorizontalGlue(),
Button("Check",Evaluate(function="Checkxs"),background=green),
Button("Show",Evaluate(function="Showxs"),background=yellow)
],
[ Button("Display First Critical Point",Evaluate(function="Critical1"),background=cyan),
Button("Display Second Critical Point",Evaluate(function="Critical2"),background=cyan),
Button("Display Third Critical Point",Evaluate(function="Critical3"),background=cyan)
],
[ halign=none,border=true,caption="Step 4(a): Evaluate f '' (x) at the given point.",
Label("f '' (",font=Font(family=Helvetica,size=16)),
TextField[TFppa](width=2,editable=false),
Label(") = ",font=Font(family=Helvetica,size=16)),
TextField[TFppa2](width=5,editable=true),
HorizontalGlue(),
Button("Check",Evaluate(function="Checkfppa"),background=green),
Button("Show",Evaluate(function="Showfppa"),background=yellow)
],
[ halign=none,border=true,caption="Step 4(b): Use the Second Derivative Test to classify the critical point.",
Label("x =",font=Font(family=Helvetica,size=16)),
TextField[TFa](width=3,editable=false),
RadioButton[Radio1]("Local Min",value=false,group=RB1),
RadioButton[Radio2]("Local Max", value=false,group=RB1),
RadioButton[Radio3]("Test Fails", value=false,group=RB1),
HorizontalGlue(),
Button("Check",Evaluate(function="CheckClass"),background=green),
Button("Show",Evaluate(function="ShowClass"),background=yellow)
],
[ TextField[reply](width=50,halign=center,editable=false,background=turquoise)
],
[ halign=none, background=ColorFooter,
Label("Programmer: Nicole Wanlass", font=FontFooter),
HorizontalGlue(),
Label("Copyright: P. Yasskin 2008", font=FontFooter)
]
]
),
ButtonGroup[RB1]()
):Maplets[Display](CriticalPoints);