Work along a CurveJohn Kirgis & James Deck253 Honors Spring 2009restart:with(Maplets[Tools]): with(Maplets[Elements]): with(plots): with(plottools):with(VecCalc):VCalias:
StartEngine();randomize():lightorange:="#FFB300":
lightcyan:="#DDFFFF":
lightblue:="#AAAAFF":ColorFooter:=lightcyan:
FontFooter:=Font("helvetica",10):randpow:=rand(-2..2):
randcase:=rand(1..3):
randt1:=rand(1..3):
dt:=rand(1..3):ask:=proc()
global rt, Fxyz, curveplot, t1, t2, v, Ft, dotprod, I1, I2;
local case, p, q, l, m, d, e, a, b, c, f, r, n;
Set(TFv="");Set(TFv(background) = lightcyan);
Set(TFF="");Set(TFF(background) = lightcyan);
Set(TFdot="");Set(TFdot(background) = lightcyan);
Set(TFWI="");Set(TFWI(background) = lightcyan);
Set(TFW="");Set(TFW(background) = lightcyan);
case:=randcase();
if case=1 then
a:=1; b:=2; c:=2;
r:=randpow();
q:=randpow();
n:=randpow();
m:=randpow();
p:=randpow();
e:=randpow();
f:=randpow();
d:=(a-1)/(a*(c-1))*(a*p+b*q+c*r)-b*e+c*f;
l:=(a-1)/(a*(b-1))*(a*p+b*q+c*r)-b*m-c*n;
rt:=[t^a,t^b,t^c];
Fxyz:=[x^p*y^q*z^r,x^l*y^m*z^n,x^d*y^e*z^f];
elif case=2 then
a:=2; b:=1; c:=2;
p:=randpow();
r:=randpow();
l:=randpow();
m:=randpow();
d:=randpow();
n:=randpow();
f:=randpow();
q:=(b-1)/(b*(a-1))*(a*l+b*m+c*n)-c*p-c*r;
e:=(b-1)/(b*(c-1))*(a*l+b*m+c*n)-a*d-c*f;
rt:=[t^a,t^b,t^c];
Fxyz:=[x^p*y^q*z^r,x^l*y^m*z^n,x^d*y^e*z^f];
else #case=3
a:=2; b:=2; c:=1;
p:=randpow();
q:=randpow();
l:=randpow();
m:=randpow();
d:=randpow();
e:=randpow();
f:=randpow();
r:=(c-1)/(c*(a-1))*(a*d+b*e+c*f)-a*p-b*q;
n:=(c-1)/(c*(b-1))*(a*d+b*e+c*f)-a*l-b*m;
rt:=[t^a,t^b,t^c];
Fxyz:=[x^p*y^q*z^r,x^l*y^m*z^n,x^d*y^e*z^f];
end if;
t1:=randt1();
t2:=t1+dt();
Set(TFFxyz=Fxyz);
Set(TFrt=rt);
Set(TFt1=t1);
Set(TFt2=t2);
v:=diff(rt,t):
Ft:=eval(Fxyz,[x=rt[1],y=rt[2],z=rt[3]]):
dotprod:=expand(Dot(Ft,v));
I1:=Int(dotprod,t=t1..t2);
I2:=int(dotprod,t=t1..t2);
curveplot:=spacecurve(rt,t=t1..t2,axes=normal,color=blue,thickness=2, orientation=[30,75]);
Set(Pcurve=curveplot);
end proc:hint_v:=proc()
Set(reply=" Take the derivative of r(t). Use square brackets [ ].")
end proc:check_v:=proc()
global v;
local userform_v;
userform_v:=Get(TFv::list):
if userform_v=v then
Set(reply="Neato!"),
Set(TFv(background) = green)
else
Set(reply="Oh, too bad. Try again."),
Set(TFv(background) = red)
end if;
end proc:show_v:=proc()
global v;
Set(TFv=v);
Set(reply=" Try for yourself next time."),
Set(TFv(background) = lightorange)
end proc:hint_F:=proc()
Set(reply=" F(x,y,z)=F(x(t),y(t),z(t)).")
end proc:check_F:=proc()
global Ft;
local userF;
userF:=Get(TFF::list):
if userF=Ft then
Set(reply="Someone deserves a cookie!"),
Set(TFF(background) = green)
else
Set(reply="Oh, too bad. Try again."),
Set(TFF(background) = red)
end if;
end proc:show_F:=proc()
global Ft;
Set(TFF=Ft);
Set(reply=" Try for yourself next time."),
Set(TFF(background) = lightorange)
end proc:hint_dot:=proc()
Set(reply=" It's a scalar quantity.")
end proc:check_dot:=proc()
global dotprod,Ft,v;
local userform_dot;
userform_dot:=Get(TFdot::`+`):
if userform_dot=dotprod then
Set(reply="Fantastic!"),
Set(TFdot(background) = green)
else
Set(reply="Oh, too bad. Try again."),
Set(TFdot(background) = red)
end if;
end proc:show_dot:=proc()
global dotprod;
Set(TFdot=dotprod);
Set(reply=" Try for yourself next time."),
Set(TFdot(background) = lightorange)
end proc:hint_WI:=proc()
Set(reply=" Just set up the integral, don't work it out yet. (Use Int, not int)")
end proc:check_WI:=proc()
global I1,I2,dotprod,t1,t2;
local userWI;
userWI:=Get(TFWI::function):
if eval(userWI)-eval(I1)=0 then
Set(reply="Super Duper!"),
Set(TFWI(background) = green)
else
Set(reply="Oh, too bad. Try again."),
Set(TFWI(background) = red)
end if;
end proc:show_WI:=proc()
global I1;
Set(TFWI=I1);
Set(reply=" Try for yourself next time."),
Set(TFWI(background) = lightorange)
end proc:hint_W:=proc()
Set(reply=" Work out the integral.")
end proc:check_W:=proc()
global I2;
local userW;
userW:=Get(TFW::realcons):
if userW=I2 then
Set(reply="Alright! I'd give you a high five, but I don't have fingers."),
Set(TFW(background) = green)
else
Set(reply="Oh, too bad. Try again."),
Set(TFW(background) = red)
end if;
end proc:show_W:=proc()
global I2;
Set(TFW=I2);
Set(reply=" Try for yourself next time."),
Set(TFW(background) = lightorange)
end proc:WorkCurve:=Maplet(onstartup=RunWindow(MAIN),
Window[MAIN](title="Work Along A Curve",
[ halign=none, valign=none, inset=0,
[ halign=none,
Button("New Problem", Evaluate(function="ask"), background=green),
HorizontalGlue(),
Button("Quit",Shutdown(), background=pink)
],
BoxColumn( halign=none,border=true,
caption="Problem Statement",
[ "Find the total work done by the force defined by the vector field F=",
MathMLViewer[TFFxyz](width=200, height=60)
],
[ "along the curve r(t)=",
MathMLViewer[TFrt](width=80, height=30),
"between t=",
TextField[TFt1](width=3, editable=false, background=white),
"and",
TextField[TFt2](width=3, editable=false, background=white),
HorizontalGlue()
]
),
[ [ border=true,
caption="Plot",
Plotter[Pcurve]("", width=285, height=285)
],
[
[ halign=none, border=true,
caption="Compute the velocity.",
"v = ",
HorizontalGlue(),
TextField[TFv](width=15, background=lightcyan),
HorizontalGlue(),
Button("Hint", Evaluate(function="hint_v"), background=yellow),
Button("Check", Evaluate(function="check_v"), background=green),
Button("Show", Evaluate(function="show_v"), background=lightorange)
],
[ halign=none, border=true,
caption="Parametrize the force F in terms of t.",
"F = ",
HorizontalGlue(),
TextField[TFF](width=15, background=lightcyan),
HorizontalGlue(),
Button("Hint", Evaluate(function="hint_F"), background=yellow),
Button("Check", Evaluate(function="check_F"), background=green),
Button("Show", Evaluate(function="show_F"), background=lightorange)
],
[ halign=none, border=true,
caption="Calculate the dot product of F and v.",
"F . v = ",
TextField[TFdot](width=15, background=lightcyan),
HorizontalGlue(),
Button("Hint", Evaluate(function="hint_dot"), background=yellow),
Button("Check", Evaluate(function="check_dot"), background=green),
Button("Show", Evaluate(function="show_dot"), background=lightorange)
],
[ halign=none, border=true,
caption="Write out the integral for the work.",
"W = ",
HorizontalGlue(),
TextField[TFWI](width=15, background=lightcyan),
HorizontalGlue(),
Button("Hint", Evaluate(function="hint_WI"), background=yellow),
Button("Check", Evaluate(function="check_WI"), background=green),
Button("Show", Evaluate(function="show_WI"), background=lightorange)
],
[ halign=none, border=true,
caption="Compute the integral for the work.",
"W = ",
HorizontalGlue(),
TextField[TFW](width=15, background=lightcyan),
HorizontalGlue(),
Button("Hint", Evaluate(function="hint_W"), background=yellow),
Button("Check", Evaluate(function="check_W"), background=green),
Button("Show", Evaluate(function="show_W"), background=lightorange)
]
]
],
TextField[reply](width=40, editable=false, background=white),
[ halign=none, background=ColorFooter,
Label("Programmers: John Kirgis & James Deck", font=FontFooter),
HorizontalGlue(),
Label("Copyright: P. Yasskin 2009", font=FontFooter)
]
])):Maplets[Display](WorkCurve);