# Computing Integrals by Converting from Rectangular to Polar Coordinates # Alex Mathew & Ryan Priest # Math 253 Honors Section 201 # Fall 2012 # Instructor: Philip Yasskin restart: with(Maplets[Tools]): with(Maplets[Elements]): with(plots): StartEngine(); randomize(): rand10:=rand(1..10): rand5:=rand(1..5): rand4:=rand(1..4): forms:=[e^(x^2+y^2), sin(x^2+y^2), cos(x^2+y^2), ln(1+(x^2+y^2)), (x^2+y^2)^(n1/2)]: polforms:=[e^(r^2), sin(r^2), cos(r^2), ln(1+r^2), r^n1]: randform:=rand(1..nops(forms)): NewIntegral:=proc() global forms, polforms, shapeform, r1, n1, tmin, tmax, polinteg, polint, Sol1; local xlo, xup, ylo, yup, integform, rectinteg, rectint; shapeform:=rand4(); r1:=rand10(); n1:=rand5(); (*This defines variables for shapeform=1.*) xlo:=-r1; xup:=r1; ylo:=-sqrt(r1^2-x^2); yup:=sqrt(r1^2-x^2); tmin:=0; tmax:=2*Pi; (*This redefines variables for shapeform<>1.*) if shapeform=2 then ylo:=0; tmin:=0; tmax:=Pi; elif shapeform=3 then xlo:=0; tmin:=-Pi/2; tmax:=Pi/2; elif shapeform=4 then xlo:=0; ylo:=0; tmin:=0; tmax:=Pi/2; end if; integform:=randform(); rectinteg:=forms[integform]; rectint:=Int(Int(rectinteg,y=ylo..yup),x=xlo..xup); polinteg:=polforms[integform]; polint:=Int(Int(polinteg*r,r=0..r1),theta=tmin..tmax); Sol1:=value(polint); Set(MMLRectInt(value)=(I=rectint)); Set(DDBShape=("Select")); Set(replyshape=""); Set(TFrmin=""); Set(TFrmax=""); Set(TFtmin=""); Set(TFtmax=""); Set(replyLim=""); Set(TFinteg=""); Set(replyinteg=""); Set(TFdiff=""); Set(replydiff=""); Set(TFPolint=""); Set(replyPolint=""); Set(TFSol=""); Set(replySol=""); Set(reply=""); end proc: Hintshape:=proc() Set (reply="Look at the bounds carefully. They describe part of or all of a circle.\nWhat part of a circle would have x only positive or only negative?\ny is only positive or only negative? How do these combine?"); end proc: Checkshape:=proc() global forms, polforms, shapeform, r1, tmin, tmax, polinteg, polint, Sol1; local usershape, usershapenum; usershape:=Get(DDBShape); if usershape="Full Circle" then usershapenum:=1; elif usershape="Upper Semicircle" then usershapenum:=2; elif usershape="Right Semicircle" then usershapenum:=3; elif usershape="Quarter Circle in Quad I" then usershapenum:=4; else usershapenum:=0; end if; if usershapenum=shapeform then Set(replyshape="Correct"); Set(reply="Great job!"); else Set(replyshape="Incorrect"); if shapeform=1 then Set(reply="Notice the bounds for both x and y run from a negative to a positive value."); elif shapeform=2 then Set(reply="Notice y is only positive in the bounds."); elif shapeform=3 then Set(reply="Notice x is only positive in the bounds."); elif shapeform=4 then Set(reply="Notice x and y are both positive in the bounds."); end if; end if; end proc: Showshape:=proc() global shapeform; if shapeform=1 then Set(DDBShape="Full Circle"); elif shapeform=2 then Set(DDBShape="Upper Semicircle"); elif shapeform=3 then Set(DDBShape="Right Semicircle"); elif shapeform=4 then Set(DDBShape="Quarter Circle in Quad I"); end if; Set(replyshape="Shown"); Set(reply="Now you know the answer. Next time try yourself."); end proc: HintLim:=proc() Set (reply="Think of how the shape of the bounds is described in polar coordinates."); end proc: CheckLim:=proc() global r1, tmin, tmax; local userrmin, userrmax, usertmin, usertmax, userlim, limans; userrmin:=Get(TFrmin::realcons, corrections=true, update=true); userrmax:=Get(TFrmax::realcons, corrections=true, update=true); usertmin:=Get(TFtmin::realcons, corrections=true, update=true); usertmax:=Get(TFtmax::realcons, corrections=true, update=true); userlim:=[userrmin,userrmax,usertmin,usertmax]; limans:=[0,r1,tmin,tmax]; if userlim=limans then Set(replyLim="Correct"); Set(reply="Great job!"); else Set(replyLim="Incorrect"); Set(reply="Look at the hint and fix the limits of r and theta."); end if; end proc: ShowLim:=proc() global r1, tmin, tmax; Set(TFrmin=0); Set(TFrmax=r1); Set(TFtmin=tmin); Set(TFtmax=tmax); Set(replyLim="Shown"); Set(reply="Now you know the answer. Next time try yourself."); end proc: Hintinteg:=proc() Set (reply="Convert the integrand from rectangular to polar coordinates. Remember:\n x^2+y^2=r^2, x=r*sin(theta) and y=r*cos(theta)."); end proc: Checkinteg:=proc() global polinteg; local userinteg; userinteg:=Get(TFinteg::algebraic, corrections=true, update=true); if userinteg=polinteg then Set(replyinteg="Correct"); Set(reply="Great job!"); else Set(replyinteg="Incorrect"); if userinteg=r*polinteg then Set(reply="Almost. Remember to leave out the Jacobian in this step."); else Set(reply="Try again."); end if; end if; end proc: Showinteg:=proc() global polinteg; Set(TFinteg=polinteg); Set(replyinteg="Shown"); Set(reply="Now you know the answer. Next time try yourself."); end proc: Hintdiff:=proc() Set (reply="What is the Jacobian associated with converting from rectangular coordinates to polar coordinates?"); end proc: Checkdiff:=proc() local userdiff; userdiff:=Get(TFdiff::algebraic, corrections=true, update=true); if userdiff=r then Set(replydiff="Correct"); Set(reply="Great job!"); else Set(replydiff="Incorrect"); Set(reply="Try again."); end if; end proc: Showdiff:=proc() Set(TFdiff=r); Set(replydiff="Shown"); Set(reply="Now you know the answer. Next time try yourself."); end proc: (*Hint is a window.*) CheckPolint:=proc() global polinteg, polint; local userPolint; userPolint:=Get(TFPolint::algebraic, corrections=true, update=true); if simplify(userPolint-polint)=0 then Set(replyPolint="Correct"); Set(reply="Great job!"); else Set(replyPolint="Incorrect"); if userPolint=Int(Int(polinteg,r=0..r1),theta=tmin..tmax) then Set(reply="Almost. Don't forget the Jacobian in the integrand!"); else Set(reply="Try again."); end if; end if; end proc: ShowPolint:=proc() global polint; Set(TFPolint=polint); Set(replyPolint="Shown"); Set(reply="Now you know the answer. Next time try yourself."); end proc: HintSol:=proc() Set (reply="Compute the integral to find the solution. Don't forget about the Jacobian!"); end proc: CheckSol:=proc() global Sol1; local userSol; userSol:=Get(TFSol::realcons, corrections=true, update=true); if userSol=Sol1 then Set(replySol="Correct"); Set(reply="Great job!"); else Set(replySol="Incorrect"); Set(reply="Try again."); end if; end proc: ShowSol:=proc() global Sol1; Set(TFSol=Sol1); Set(replySol="Shown"); Set(reply="Now you know the answer. Next time try yourself."); end proc: ToPolarMaplet:=Maplet(onstartup = RunWindow(MAIN), Window[MAIN](title="Computing Integrals by Converting from Rectangular to Polar Coordinates", [ valign=none, inset=0, spacing=0, [ Button("New Integral", Evaluate(function="NewIntegral"), background=magenta), [ border=true, caption="Goal: Compute the following integral by converting to polar coordinates:", MathMLViewer[MMLRectInt](width=300, height=100, background=white) ], Button("Quit", Shutdown(), background=pink) ], [ halign=none, border=true, caption="Step 1: Identify the shape of the region:", DropDownBox[DDBShape]("Select", ["Select", "Full Circle", "Upper Semicircle", "Right Semicircle", "Left Semicircle", "Lower Semicircle", "Quarter Circle in Quad I", "Quarter Circle in Quad II", "Quarter Circle in Quad III", "Quarter Circle in Quad IV"], background=turquoise), HorizontalGlue(), Button("Hint", Evaluate(function="Hintshape"), background=Orange), Button("Check", Evaluate(function="Checkshape"), background=green), TextField[replyshape](width=10, editable=false, background=white), Button("Show", Evaluate(function="Showshape"), background=yellow) ], BoxColumn( valign=none, border=true, caption="Step 2: Prepare to Integrate in polar coordinates:", [ halign=none, inset=0, "Limits:", TextField[TFrmin](width=3, background=turquoise), "<= r <=", TextField[TFrmax](width=3, background=turquoise), HorizontalGlue(), TextField[TFtmin](width=5, background=turquoise), "<= theta <=", TextField[TFtmax](width=5, background=turquoise), HorizontalGlue(), Button("Hint", Evaluate(function="HintLim"), background=Orange), Button("Check", Evaluate(function="CheckLim"), background=green), TextField[replyLim](width=10,editable=false, background=white), Button("Show",Evaluate(function="ShowLim"), background=yellow) ], [ halign=none, inset=0, "Integrand:", Label[Linteg]("f(x,y) ="), TextField[TFinteg](width=27, background=turquoise), HorizontalGlue(), Button("Hint", Evaluate(function="Hintinteg"), background=Orange), Button("Check", Evaluate(function="Checkinteg"), background=green), TextField[replyinteg](width=10,editable=false, background=white), Button("Show",Evaluate(function="Showinteg"), background=yellow) ], [ halign=none, inset=0, "Area differential: dA = dx dy =", TextField[TFdiff](width=5, background=turquoise), "dr dtheta", HorizontalGlue(), Button("Hint", Evaluate(function="Hintdiff"), background=Orange), Button("Check", Evaluate(function="Checkdiff"), background=green), TextField[replydiff](width=10,editable=false, background=white), Button("Show", Evaluate(function="Showdiff"), background=yellow) ] ), BoxColumn( valign=none, border=true, caption="Step 3: Integrate in Polar Coordinates:", halign=none, [ halign=none, inset=0, "Set up: I =", TextField[TFPolint](width=32, background=turquoise), HorizontalGlue(), Button("Hint", RunWindow(PolIntHint), background=Orange), Button("Check", Evaluate(function="CheckPolint"), background=green), TextField[replyPolint](width=10,editable=false, background=white), Button("Show", Evaluate(function="ShowPolint"), background=yellow) ], [ halign=none, inset=0, "Evaluate: I =", TextField[TFSol](width=25, background=turquoise), HorizontalGlue(), Button("Hint", Evaluate(function="HintSol"), background=Orange), Button("Check", Evaluate(function="CheckSol"), background=green), TextField[replySol](width=10,editable=false, background=white), Button("Show", Evaluate(function="ShowSol"), background=yellow) ] ) , [ halign=none, TextBox[reply](width=40, height=3, editable=false, background=white) ], [ "Instuctor: Philip Yasskin", "Programmers: Alex Mathew and Ryan Priest", "Copyright: Yasskin 2012" ] ] ), Window[PolIntHint](title="Polar Integral Hint", [ "Enter your answer in this form:", TextField("Int(Int(f(r,theta)*Jacobian,r=rmin..rmax),theta=thetamin..thetamax)", width=50), "so that the integr al is represented as:", [MathMLViewer[MMLPolIntHint]( value=Int(Int(f(r,theta)*Jacobian,r=r[min]..r[max]),theta=theta[min]..theta[max]), width=250, height=100)], Button("Close", CloseWindow(PolIntHint), background=pink) ] ) ): Maplets[Display]( ToPolarMaplet );