Vertical AsymptotesSida Wang, Ryan Stawaiszrestart:with(Maplets[Tools]): with(Maplets[Elements]): with(plots):
StartEngine();randomize():lightorange:="#FFB300":great:=["Great Job!","Radical, Man!","Wow, You're a Genius!","Right On!","Sweet!","Awesome!","Way to go!","All The Way!","Cool!","I Wish I Was as Smart as You!","Holy Smokes! You're Right!","Get Your Nerd On!","Mad Skillz!","Who are You, John Nash?","Who are You, Albert Einstein?","High Five!","Dang, You are Smart!","Bam! Right on Target"]:randgreat:=rand(1..nops(great)):sorry:=["Try Again.","Back to the Drawing Board.","So Close, Yet So Far","Double Check Your Answer.","Are You Sure that's Right?","Is that Your Final Answer?","I Don't Think that's Right...","Oops.","Missed by a Hair.","Let's recheck that.","Not Bad, but Not Good.","You're not on your A Game.","Not Everyone can be Einstein..."]:randsorry:=rand(1..nops(sorry)):randroot:=rand(-9..9):
randcancel:=rand(0..5):
randexpon:=rand(0..4):
randt:=rand(0..1):ask:=proc()
global func, factored, num, denomi, zeroes;
local a,b,c,d,e,p,q,r,s,t;
func:=1;
while func::realcons do
a:=randroot();
b:=randroot();
c:=randroot();
d:=randroot();
a:=`if`(randcancel()>1,c,a);
b:=`if`(randcancel()>1,d,b);
p:=randexpon();
q:=randexpon();
r,s,t:=0,0,0;
while r=0 and s=0 and t=0 do
r:=randexpon();
s:=randexpon();
t:=randt();
end do;
p:=`if`(p>1,1,p);
q:=`if`(q>1,1,q);
r:=`if`(r>1,1,r);
s:=`if`(s>1,1,s);
num:=(x-a)^p*(x-b)^q;
denomi:=x^t*(x-c)^r*(x-d)^s;
func:=expand(num)/expand(denomi);
end do;
factored:=factor(func);
zeroes:={solve((denomi/num)=0)};
Set(MMLfn(value)=MathML[Export](func));
Set(TFfactored="");
Set(MMLfactored(value)="");
Set(TFzeroes="");
Set(CBnone=false);
Set(myplot=plot(0, x=-10..10, -25..25, color=black));
Set(reply="");
end proc:preview_factored:=proc()
local user_factored;
user_factored:=Get(TFfactored::algebraic);
Set(MMLfactored(value)=MathML[Export](user_factored));
end proc:check_factored:=proc()
global factored;
local user_factored;
user_factored:=Get(TFfactored::algebraic);
if user_factored=factored then
Set(reply=great[randgreat()]);
else
Set(reply=sorry[randsorry()]);
end if;
end proc:show_factored:=proc()
global factored;
Set(TFfactored=factored);
Set(MMLfactored(value)=MathML[Export](factored));
end proc:check_zeroes:=proc()
global zeroes;
local user_zeroes, user_none;
user_zeroes:=Get(TFzeroes);
user_none:=Get(CBnone);
if (user_zeroes="" and not user_none) or
(user_zeroes<>"" and user_none) then
Set(reply="Either enter the zeroes of check none, (not both).");
return;
end if;
user_zeroes:={parse(user_zeroes)};
if not type(user_zeroes,set(integer)) then
Set(reply="The zeroes should be integers. Try again.");
return;
end if;
if user_none and zeroes={} or
user_zeroes=zeroes then
Set(reply=great[randgreat()]);
else
Set(reply=sorry[randsorry()]);
end if;
end proc:show_zeroes:=proc()
global zeroes;
if zeroes={} then
Set(CBnone=true);
Set(TFzeroes="");
else
Set(TFzeroes=convert(zeroes,string)[2..-2]);
Set(CBnone=false);
end if;
end proc:plotfunc:=proc()
global func, zeroes;
local p1;
p1:=plot(func, x=-10..10, -25..25, discont=true, thickness=2, color=blue);
Set(myplot=p1)
end proc:VerticalAsymptotes:=Maplet(onstartup=RunWindow(MAIN),
Window[MAIN](title="Vertical Asymptotes",
[ halign=none, valign=none, inset=0, spacing=0,
[ halign=none,
Button("New Function", Evaluate (function="ask"), background=magenta),
HorizontalGlue(),
Button("Quit", Shutdown(), background=pink)
],
[ halign=none, valign=none, inset=0, spacing=0,
[ halign=none, valign=none, inset=0, spacing=0,
[ halign=none, border=true,
caption="Find all vertical asymptotes of the function",
"f(x) =",
MathMLViewer[MMLfn](width=200, height=75, background=white)
],
BoxColumn( halign=none, valign=none, inset=0, spacing=0, border=true,
caption="Factor the numerator and denominator and cancel any common factors",
[ halign=none,
"f(x) =",
TextField[TFfactored](width=20, background=turquoise),
Button("Preview", Evaluate(function="preview_factored"), background=lightorange),
Button("Check", Evaluate(function="check_factored"), background=green),
Button("Show", Evaluate(function="show_factored"), background=lightorange)
],
[ halign=none,
"f(x) =",
MathMLViewer[MMLfactored](width=200, height=75, background=white)
]
),
[ border=true,
caption="Find the zeroes of the denominator.",
"x = ",
TextField[TFzeroes](width=10, background=turquoise),
CheckBox[CBnone]("None"),
Button("Check", Evaluate(function="check_zeroes"), background=green),
Button("Show", Evaluate(function="show_zeroes"), background=lightorange)
]
],
[ halign=none, valign=none, border=true,
caption="Plot",
[ Plotter[myplot](width=250, height=250)
],
[ Button("Plot It", Evaluate(function="plotfunc"), background=tan)
]
]
],
[TextField[reply](width=60, editable=false, background=white)
],
[ halign=none, background="#DDFFFF", inset=0, spacing=0,
"Programmers: Sida Wang, Ryan Stawaisz",
HorizontalGlue(),
"@ Copyright: P. Yasskin 2007"
]
]
)
):Maplets[Display]( VerticalAsymptotes );