Converting an Integral from Rectangular to Polar Coordinates
Programmers: Will Harris & Matt Milanowski
Math 253 Honors Section 201
Fall 2012
Instructor: Philip Yasskinrestart:with(Maplets[Tools]): with(Maplets[Elements]): with(plots):
StartEngine();randomize():alias(e=exp(1)):rand5:= rand(1..5):rand7:= rand(1..7):rand3:= rand(0..3):shapes:=["Full Circle","Semicircle","Semicircle","Quarter Circle"]:fns:=[p->p,p->exp(p),p->sin(p),p->cos(p),p->sqrt(p),p->p^2]:rand6:= rand(1..6):NewIntegral:=proc()
global A,C,fxy,frth,f,y2,y1,x2,x1,xyintegral,rthintegral,s,r1,r2,th1a,th1b,th2a,th2b,rthintegralans,rthintegralansnoJac,cor1,cor2,cor3,cor4;
local rthintegralnoJac;
A:=rand5();
C:=rand7();
s:=rand3();
fxy:=x^2/A^2+y^2/A^2;
frth:=r^2/A^2;
f:=fns[rand6()];
x2:=C;
y2:=sqrt(C^2-x^2);
r1:=0;
r2:=C;
if s=0 then
x1:=-C;
y1:=-sqrt(C^2-x^2);
th1a:=0;
th1b:=0;
th2a:=2*Pi;
th2b:=2*pi;
elif s=1 then
x1:=0;
y1:=-sqrt(C^2-x^2);
th1a:=-Pi/2;
th1b:=-pi/2;
th2a:=Pi/2;
th2b:=pi/2;
elif s=2 then
x1:=-C;
y1:=0;
th1a:=0;
th1b:=0;
th2a:=Pi;
th2b:=pi;
else
x1:=0;
y1:=0;
th1a:=0;
th1b:=0;
th2a:=Pi/2;
th2b:=pi/2;
end if;
xyintegral:=Int(Int(f(fxy),y=y1..y2),x=x1..x2);
rthintegral:=Int(Int(f(frth)*r,r=r1..r2),theta=th1a..th2a);
rthintegralnoJac:=Int(Int(f(frth),r=r1..r2),theta=th1a..th2a);
rthintegralans:=value(rthintegral);
rthintegralansnoJac:=value(rthintegralnoJac);
cor1:=false:
cor2:=false:
cor3:=false:
cor4:=false:
Set(MMLxyintegral(value)=xyintegral);
Set(replyshape="");
Set(TFr1="");
Set(TFr2="");
Set(replyr="");
Set(TFth1="");
Set(TFth2="");
Set(replyth="");
Set(TFf="");
Set(replyf="");
Set(TFda="");
Set(replyda="");
Set(TFint="");
Set(replyint="");
Set(reply="");
Set(DBBshape="Select");
Set(MMLrthintegral="");
end proc:Hintshape:=proc()
Set(reply="Try manipulating one of the limits into a recognizable equation and/or sketching the x and y limits out.")
end proc:Checkshape:=proc()
global A,C,fxy,frth,f,y2,y1,x2,x1,xyintegral,rthintegral,s,r1,r2,th1a,th1b,th2a,th2b,rthintegralans,rthintegralansnoJac,cor1,cor2,cor3,cor4;
local usershape;
usershape:=Get(DBBshape);
if usershape=shapes[s+1] then
Set(replyshape="Correct");
Set(reply="Great job!");
elif usershape="Select" then
Set(replyshape="");
Set(reply="Please make a choice.");
else
Set(replyshape="Incorrect");
Set(reply="");
end if;
end proc:Showshape:=proc()
global s;
Set(DBBshape=shapes[s+1]);
Set(replyshape="Shown");
Set(reply="Now you know the answer. Next time try yourself.");
end proc:Hintr:=proc()
Set(reply="From your sketch of the shape, what is the largest and smallest radius?")
end proc:Checkr:=proc()
global r1,r2,cor1;
local userr1,userr2;
userr1:=Get(TFr1::algebraic, corrections=true, update=true);
userr2:=Get(TFr2::algebraic, corrections=true, update=true);
if simplify(userr1-r1)=0 and simplify(userr2-r2)=0 then
Set(replyr="Correct");
Set(reply="Great job!");
cor1:=true;
elif simplify(userr1-r1)=0 then
Set(replyr="Incorrect");
Set(reply="The upper limit is incorrect.")
elif simplify(userr2-r2)=0 then
Set(replyr="Incorrect");
Set(reply="The lower limit is incorrect.")
else
Set(replyr="Incorrect");
Set(reply="Both limits are incorrect.");
end if;
end proc:Showr:=proc()
global r1,r2,cor1;
Set(TFr1=r1);
Set(TFr2=r2);
Set(replyr="Shown");
Set(reply="Now you know the answer. Next time try yourself.");
cor1:=true;
end proc:Hintth:=proc()
Set(reply="Your sketch and knowledge of how to determine the theta value should help you determine the limits of theta.")
end proc:Checkth:=proc()
global th1a,th1b,th2a,th2b,cor2,pi;
local userth1,userth2;
userth1:=Get(TFth1::algebraic, corrections=true, update=true);
userth2:=Get(TFth2::algebraic, corrections=true, update=true);
if (simplify(userth1-th1a)=0 or simplify(userth1-th1b)=0) and
(simplify(userth2-th2a)=0 or simplify(userth2-th2b)=0) then
Set(replyth="Correct");
Set(reply="Great job!");
cor2:=true;
elif (simplify(userth1-th1a)=0 or simplify(userth1-th1b)=0) then
Set(replyth="Incorrect");
Set(reply="The upper limit is incorrect.")
elif (simplify(userth2-th2a)=0 or simplify(userth2-th2b)=0) then
Set(replyth="Incorrect");
Set(reply="The lower limit is incorrect.")
else
Set(replyth="Incorrect");
Set(reply="Both limits are incorrect.");
end if;
end proc:Showth:=proc()
global th1a,th2a,cor2;
Set(TFth1=th1a);
Set(TFth2=th2a);
Set(replyth="Shown");
Set(reply="Now you know the answer. Next time try yourself.");
cor2:=true;
end proc:Hintf:=proc()
Set(reply="Remember: x^2+y^2=r^2, x=r*cos(theta), and y=r*sin(theta)")
end proc:Checkf:=proc()
global frth,f,cor3;
local userfrth;
userfrth:=Get(TFf::algebraic, corrections=true, update=true);
if simplify(userfrth-f(frth))=0 then
Set(replyf="Correct");
Set(reply="Great job!");
cor3:=true;
else
Set(replyf="Incorrect");
Set(reply="Not quite. Try Again!");
end if;
end proc:Showf:=proc()
global frth,f,cor3;
Set(TFf=f(frth));
Set(replyf="Shown");
Set(reply="Now you know the answer. Next time try yourself.");
cor3:=true;
end proc:Hintda:=proc()
Set(reply="Be sure to remember the Jacobian when your function is in terms of r and theta!")
end proc:Checkda:=proc()
global cor4;
local userda;
userda:=Get(TFda::algebraic, corrections=true, update=true);
if simplify(userda-r*dr*dtheta)=0 then
Set(replyda="Correct");
Set(reply="Great job!");
cor4:=true;
elif simplify(userda-dr*dtheta)=0 then
Set(replyda="Incorrect");
Set(reply="Don't forget the Jacobian!");
elif simplify(userda-r)=0 then
Set(replyda="Incorrect");
Set(reply="Don't forget the differentials!");
else
Set(replyda="Incorrect");
Set(reply="");
end if;
end proc:Showda:=proc()
global cor4;
Set(TFda=r*dr*dtheta);
Set(replyda="Shown");
Set(reply="Now you know the answer. Next time try yourself.");
cor4:=true;
end proc:Displayint:=proc()
global rthintegral,cor1,cor2,cor3,cor4;
if cor1 and cor2 and cor3 and cor4 then
Set(MMLrthintegral=rthintegral);
else
Set(reply="Find the limits, integrand and differential of the integral first.");
end if;
end proc:Hintint:=proc()
Set(reply="You may need to use a u-substitution.")
end proc:Checkint:=proc()
global rthintegralans,rthintegralansnoJac;
local userint;
userint:=Get(TFint::algebraic, corrections=true, update=true);
if simplify(userint-rthintegralans)=0 then
Set(replyint="Correct");
Set(reply="Great job!");
elif simplify(userint-rthintegralansnoJac)=0 then
Set(replyint="Incorrect");
Set(reply="You forgot the Jacobian.");
else
Set(replyint="Incorrect");
Set(reply="");
end if;
end proc:Showint:=proc()
global rthintegralans;
Set(TFint=rthintegralans);
Set(replyint="Shown");
Set(reply="Now you know the answer. Next time try yourself.");
end proc:PolarIntegralMaplet:=Maplet(onstartup = RunWindow(MAIN),
Window[MAIN](title="Calculating a Polar Integral",
[ valign=none, inset=0, spacing=0,
[ Button("New Integral", Evaluate(function="NewIntegral"), background=magenta),
[ valign=none, inset=0,spacing=0, border=true,
caption="Goal: Compute the integral",
[ halign=none,
"I = ",
MathMLViewer[MMLxyintegral](value=(Int(Int(f(x,y),y=y1..y2),x=x1..x2)), width=300, height=90, background=white)
],
[ halign=none,
"by converting it to polar coordinates.",
HorizontalGlue()
]
],
Button("Quit", Shutdown(), background=pink)
],
[ halign=none, border=true,
caption="Select the Shape you are Integrating",
DropDownBox[DBBshape]("Select",["Select","Full Circle","Semicircle","Quarter Circle"]),
HorizontalGlue(),
HorizontalGlue(),
HorizontalGlue(),
Button("Hint", Evaluate(function="Hintshape"), background=Orange),
Button("Check", Evaluate(function="Checkshape"), background=green),
TextField[replyshape](width=10, background=white),
Button("Show", Evaluate(function="Showshape"), background=yellow)
],
BoxColumn( valign=none, inset=0, spacing=0, border=true,
caption="Convert Integral to Polar",
[ halign=none,
"Limits of r:",
HorizontalGlue(),
TextField[TFr1](width=4, background=turquoise),
"<= r <=",
TextField[TFr2](width=4, background=turquoise),
HorizontalGlue(),
Button("Hint", Evaluate(function="Hintr"), background=Orange),
Button("Check", Evaluate(function="Checkr"), background=green),
TextField[replyr](width=10, background=white),
Button("Show", Evaluate(function="Showr"), background=yellow)
],
[ halign=none,
"Limits of theta:",
HorizontalGlue(),
TextField[TFth1](width=5, background=turquoise),
"<= theta <=",
TextField[TFth2](width=5, background=turquoise),
HorizontalGlue(),
Button("Hint",Evaluate(function="Hintth"), background=Orange),
Button("Check",Evaluate(function="Checkth"), background=green),
TextField[replyth](width=10, background=white),
Button("Show", Evaluate(function="Showth"), background=yellow)
],
[ halign=none,
"f(r,theta) = ",
TextField[TFf](width=10, background=turquoise),
HorizontalGlue(),
Button("Hint",Evaluate(function="Hintf"), background=Orange),
Button("Check", Evaluate(function="Checkf"), background=green),
TextField[replyf](width=10, background=white),
Button("Show", Evaluate(function="Showf"), background=yellow)
],
[ halign=none,
"dA = dx dy =",
TextField[TFda](width=10, background=turquoise),
HorizontalGlue(),
Button("Hint",Evaluate(function="Hintda"), background=Orange),
Button("Check", Evaluate(function="Checkda"), background=green),
TextField[replyda](width=10, background=white),
Button("Show", Evaluate(function="Showda"), background=yellow)
],
[ Button("Display Polar Integral", Evaluate(function="Displayint"), background=turquoise),
"I = ",
MathMLViewer[MMLrthintegral](value=(Int(Int(f(r,theta)*r,r=r1..r2),theta=theta1..theta2)), width=200, height=100, background=white)]
),
[ halign=none, border=true,
caption="Compute Polar Integral",
"I =",
TextField[TFint](width=25, background=turquoise),
HorizontalGlue(),
Button("Hint", Evaluate(function="Hintint"), background=Orange),
Button("Check", Evaluate(function="Checkint"), background=green),
TextField[replyint](width=10, background=white),
Button("Show", Evaluate(function="Showint"), background=yellow)
],
[ halign=none,
TextBox[reply](width=40, height=2, editable=false, background=white)
],
[ "Instuctor: Philip Yasskin",
"Programmers: Will Harris and Matt Milanowski",
"Copyright: Yasskin 2012"
]
]
)
):Maplets[Display]( PolarIntegralMaplet );