Identifying Quadratic Surfaces from EquationsProgrammers: Tyler Buffington and Kyle BaylisMath 253 Honors Section 202Fall 2012Instructor: Philip Yasskinrestart:with(Maplets[Tools]):
with(Maplets[Elements]):
with(plots):
StartEngine();randomize():randpm3:=rand(-3..3):rand3:=rand(1..3):rand6:=rand(1..6):randNeg:=rand(0..1):(*quads:=["Sphere", "Ellipsoid", "Hyperboloid of 1 Sheet", "Hyperboloid of 2 Sheets", "Cone", "Elliptic Paraboloid", "Hyperbolic Paraboloid", "Elliptic Cylinder", "Hyperbolic Cylinder", "Parabolic Cylinder"]:*)quads:=["Sphere", "Ellipsoid", "Hyperboloid of 1 Sheet", "Hyperboloid of 2 Sheets ", "Cone", "Elliptic Paraboloid", "Hyperbolic Paraboloid"]:randtype:=rand(1..nops(quads)):(*plot0:=plot3d(0,x=-3..3, y=-3..3, view=-3..3, axes=normal, style=surface, color=white):*)twopos:=[ [-1,1,1], [1,-1,1], [1,1,-1] ]:twoneg:=[ [1,-1,-1], [-1,1,-1], [-1,-1,1] ]:(*one0pos:=[ [1,1,0], [1,0,1], [0,1,1] ]:*)(*one0neg:=[ [-1,1,0], [1,-1,0], [1,0,-1], [-1,0,1], [0,1,-1], [0,-1,1] ]:*)
ask:=proc()
global quadtype, correctEq;
local a0,b0,c0, lcmabc, p0, q0, r0, axis, axis6, flip, updown, parabtype, ans, expandedEq
(*correctGraph,*);
a0:=rand3();
b0:=rand3();
c0:=rand3();
lcmabc:=ilcm(a0,b0,c0);
p0:=randpm3();
q0:=randpm3();
r0:=randpm3();
axis:=rand3();
axis6:=rand6();
flip:=(-1)^randNeg();
updown:=(-1)^randNeg();
parabtype:=randNeg();
ans:=0;
quadtype:=randtype();
if quadtype=1 then (* Sphere *)
correctEq:=(x-p0)^2+(y-q0)^2+(z-r0)^2=a0^2;
expandedEq:=flip*expand(lhs(correctEq)-rhs(correctEq))=0;
elif quadtype=2 then (* Ellipsoid *)
while nops({a0,b0,c0})=1 do
c0:=rand3();
end do;
correctEq:=(x-p0)^2/a0^2+(y-q0)^2/b0^2+(z-r0)^2/c0^2=1;
expandedEq:=flip*lcmabc^2*expand(lhs(correctEq)-rhs(correctEq))=0;
elif quadtype=3 then (* Hyperboloid of 1 Sheet *)
correctEq:=twopos[axis,1]*(x-p0)^2/a0^2+twopos[axis,2]*(y-q0)^2/b0^2+twopos[axis,3]*(z-r0)^2/c0^2=1;
expandedEq:=flip*lcmabc^2*expand(lhs(correctEq)-rhs(correctEq))=0;
elif quadtype=4 then (* Hyperboloid of 2 Sheets *)
correctEq:=twoneg[axis,1]*(x-p0)^2/a0^2+twoneg[axis,2]*(y-q0)^2/b0^2+twoneg[axis,3]*(z-r0)^2/c0^2=1;
expandedEq:=flip*lcmabc^2*expand(lhs(correctEq)-rhs(correctEq))=0;
elif quadtype=5 then (* Cone *)
correctEq:=twopos[axis,1]*(x-p0)^2/a0^2+twopos[axis,2]*(y-q0)^2/b0^2+twopos[axis,3]*(z-r0)^2/c0^2=0;
expandedEq:=flip*lcmabc^2*expand(lhs(correctEq)-rhs(correctEq))=0;
elif quadtype=6 and axis=1 then (* Elliptic Paraboloid *)
correctEq:=updown*((z-r0)^2/c0^2+(y-q0)^2/b0^2)+(x-p0)=0;
expandedEq:=flip*lcmabc^2*expand(lhs(correctEq)-rhs(correctEq))=0;
elif quadtype=6 and axis=2 then (* Elliptic Paraboloid *)
correctEq:=updown*((x-p0)^2/a0^2+(z-r0)^2/c0^2)+(y-q0)=0;
expandedEq:=flip*lcmabc^2*expand(lhs(correctEq)-rhs(correctEq))=0;
elif quadtype=6 and axis=3 then (* Elliptic Paraboloid *)
correctEq:=updown*((x-p0)^2/a0^2+(y-q0)^2/b0^2)+(z-r0)=0;
expandedEq:=flip*lcmabc^2*expand(lhs(correctEq)-rhs(correctEq))=0;
elif quadtype=7 and axis=1 then (* Hyperbolic Paraboloid *)
correctEq:=updown*((x-p0)^2/a0^2-(y-q0)^2/b0^2)-(z-r0)=0;
expandedEq:=flip*lcmabc^2*expand(lhs(correctEq)-rhs(correctEq))=0;
elif quadtype=7 and axis=2 then (* Hyperbolic Paraboloid *)
correctEq:=updown*((z-r0)^2/c0^2-(y-q0)^2/b0^2)-(x-p0)=0;
expandedEq:=flip*lcmabc^2*expand(lhs(correctEq)-rhs(correctEq))=0;
elif quadtype=7 and axis=3 then (* Hyperbolic Paraboloid *)
correctEq:=updown*((x-p0)^2/a0^2-(z-r0)^2/c0^2)-(y-q0)=0;
expandedEq:=flip*lcmabc^2*expand(lhs(correctEq)-rhs(correctEq))=0;
(*
elif quadtype=8 then (* Elliptic Cylinder *)
correctEq:=flip*(one0pos[axis,1]*(x-p0)^2/a0^2+one0pos[axis,2]*(y-q0)^2/b0^2+one0pos[axis,3]*(z-r0)^2/c0^2)=flip;
expandedEq:=expand(lhs(correctEq)-rhs(correctEq))=0;
elif quadtype=9 then (* Hyperbolic Cylinder *)
correctEq:=flip*(one0neg[axis6,1]*(x-p0)^2/a0^2+one0neg[axis6,2]*(y-q0)^2/b0^2+one0neg[axis6,3]*(z-r0)^2/c0^2)=flip;
expandedEq:=expand(lhs(correctEq)-rhs(correctEq))=0;
elif quadtype=10 then (* Parabolic Cylinder *)
correctEq:=(x-p0)^2/a0^2-(y-q0)/b0=0; (*Revise*)
expandedEq:=expand(lhs(correctEq)-rhs(correctEq))=0;
*)
end if;
Set(unsolvedEq=expandedEq);
Set(compSqReply=" ", compSqReply(background)=white);
Set(compSq=" "):
Set(idQuadReply=" ", idQuadReply(background)=white);
Set(idQuad="Select");
(*Set(graphReply=" ");*)
Set(hintBox=" ");
(*
Set(PL1=plot0);
Set(PL2=plot0);
Set(PL3=plot0);
Set(PL4=plot0);
Set(RP1=false);
Set(RP2=false);
Set(RP3=false);
Set(RP4=false);
makeGraphs();
*)
end proc:compSqHint:=proc()
Set(hintBox="Complete the square for x, y, and z. For example: x^2 + 2*q*x = (x+q)^2 - q^2");
end proc:compSqCheck:=proc()
global correctEq;
local userEq;
userEq:=Get(compSq::equation, corrections=true, update=true):
if userEq=correctEq then
Set(compSqReply="Correct!", compSqReply(background)=green);
Set(hintBox="Nice job! You are a math wiz!");
else
Set(compSqReply="Incorrect", compSqReply(background)=red);
Set(hintBox="Try again, you can do it! Click the hint button if you need help.");
end if;
end proc:compSqShow:=proc()
global correctEq;
Set(compSq=correctEq):
Set(compSqReply="Shown", compSqReply(background)=yellow);
Set(hintBox="Read the textbook and try again.");
end proc:idQuadHint:=proc()
Set(hintBox="Look at the powers of x, y and z and the signs of the coefficients.");
end proc:idQuadCheck:=proc()
global quadtype;
local userAnswer;
userAnswer:=Get(idQuad):
if userAnswer=quads[quadtype] then
Set(idQuadReply="Correct!", idQuadReply(background)=green);
Set(hintBox="Nice! You sure know your quadratics!");
(*displayGraphs()*);
else
Set(idQuadReply="Incorrect", idQuadReply(background)=red);
Set(hintBox="Try again.");
end if;
end proc:idQuadShow:=proc()
global quadtype;
Set(idQuad=quads[quadtype]);
Set(idQuadReply="Shown", idQuadReply(background)=yellow);
Set(hintBox="Read the textbook and try again.");
(*displayGraphs()*);
end proc:(*
makeGraphs:=proc()
global pl, quadtype, correctEq,ans,a,b,c,d,parabtype, choice;
local a1,b1,c1,d1,a2,b2,c2,d2,a3,b3,c3,d3,
i, randNeg2, randNeg3, randNeg4;
choice:=combinat[randperm](4);
for i from 1 to 4 do
if choice[i]=1 then
ans:=i
end if;
end do;
a1:=rand3();
while a1=a do
a1:=rand3();
end do;
b1:=rand3();
while b1=b do
b1:=rand3();
end do;
c1:=randpm3();
while c1=c do
c1:=randpm3();
end do;
d1:=randpm3();
while d1=d do
d1:=randpm3();
end do;
randNeg2:=randNeg();
a2:=rand3();
while a2=a or a2=a1 do
a2:=rand3();
end do;
b2:=rand3();
while b2=b or b2=b1 do
b2:=rand3();
end do;
c2:=randpm3();
while c2=c or c2=c1 do
c2:=randpm3();
end do;
d2:=randpm3();
while d2=d or d2=d1 do
d2:=randpm3();
end do;
randNeg3:=randNeg();
a3:=rand3();
b3:=rand3();
c3:=randpm3();
while c3=c or c3=c1 or c3=c2 do
c3:=randpm3();
end do;
d3:=randpm3();
while d3=d or d3=d1 or d3=d2 do
d3:=randpm3();
end do;
randNeg4:=randNeg();
if quadtype=1 then
pl[1]:=implicitplot3d(correctEq,x=p0-a..p0+a, y=q0-a..q0+a, z=r0-a..r-+a grid=[49,49,49], scaling=constrained):
pl[2]:=implicitplot3d((x+c)^2+(y+d)^2=a^2,x=(-1)*c-a..(-1)*c+a, y=(-1)*d-a..(-1)*d+a, grid=[81,81], scaling=constrained):
pl[3]:=implicitplot3d((x-c2)^2/a2^2+(y-d2)^2/b2^2=1,x=c2-a2..c2+a2, y=d2-b2..d2+b2, grid=[81,81], scaling=constrained):
pl[4]:=implicitplot3d((x-c3)^2/a3^2+(y-d3)^2/b3^2=1,x=c3-a3..c3+a3, y=d3-b3..d3+b3, grid=[81,81], scaling=constrained):
elif quadtype=2 then
pl[1]:=implicitplot3d(correctEq,x=c-a..c+a, y=d-b..d+b, grid=[81,81], scaling=constrained):
pl[2]:=implicitplot3d((x+c)^2/a^2+(y+d)^2/b^2=1,x=(-1)*c-a..(-1)*c+a, y=(-1)*d-b..(-1)*d+b, grid=[81,81], scaling=constrained):
pl[3]:=implicitplot3d((x-c2)^2/a2^2+(y-d2)^2/b2^2=1,x=c2-a2..c2+a2, y=d2-b2..d2+b2, grid=[81,81], scaling=constrained):
pl[4]:=implicitplot3d((x-c3)^2/a3^2+(y-d3)^2/b3^2=1,x=c3-a3..c3+a3, y=d3-b3..d3+b3, grid=[81,81], scaling=constrained):
elif quadtype=3 then
pl[1]:=implicitplot3d(correctEq,x=c-5..c+5, y=d-5..d+5, grid=[81,81], scaling=constrained);
pl[2]:=implicitplot3d(lhs(correctEq)=-rhs(correctEq),x=c-5..c+5, y=d-5..d+5, grid=[81,81], scaling=constrained);
(*pl[2]:=implicitplot3d((-1)^randNeg2*( (x-c1)^2/a1^2-(y-d1)^2/b1^2 )=1,x=c1-5..c1+5, y=d1-5..d1+5, grid=[81,81], scaling=constrained):*)
pl[3]:=implicitplot3d((lhs(correctEq)*(-1)=rhs(correctEq)),x=c-5..c+5, y=d-5..d+5, grid=[81,81], scaling=constrained):
pl[4]:=implicitplot3d((-1)^randNeg4*( (x-c3)^2/a3^2-(y-d3)^2/b3^2 )=1,x=c3-5..c3+5, y=d3-5..d3+5, grid=[81,81], scaling=constrained):
elif quadtype=4 then
pl[1]:=implicitplot3d(correctEq,x=c-a..c+a, y=d-b..d+b, grid=[81,81], scaling=constrained):
pl[2]:=implicitplot3d((lhs(correctEq)*(-1)=rhs(correctEq)),x=c-7..c+7, y=d-7..d+7, grid=[81,81], scaling=constrained):
pl[3]:=implicitplot3d(y=a*(x-c2)^2+d2,x=c2-5..c2+5, y=d2-5..d2+5, grid=[81,81], scaling=constrained):
if parabtype=1 then
pl[4]:=implicitplot3d(y=(-1)^randNeg4*a*(x-c)^2+d,x=c-5..c+5, y=d-5..d+5, grid=[81,81], scaling=constrained):
else
pl[4]:=implicitplot3d(x=(-1)^randNeg4*a*(y-d)^2+c,x=c-5..c+5, y=d-5..d+5, grid=[81,81], scaling=constrained):
end if;
elif quadtype=5 then
pl[1]:=implicitplot3d(correctEq,x=c-5..c+5, y=d-5..d+5, grid=[81,81], scaling=constrained);
pl[2]:=implicitplot3d((-1)^randNeg2*( (x-c1)^2/a1^2-(y-d1)^2/b1^2 )=0,x=c1-5..c1+5, y=d1-5..d1+5, grid=[81,81], scaling=constrained):
pl[3]:=implicitplot3d((-1)^randNeg3*( (x-c2)^2/a2^2-(y-d2)^2/b2^2 )=0,x=c2-5..c2+5, y=d2-5..d2+5, grid=[81,81], scaling=constrained):
pl[4]:=implicitplot3d((-1)^randNeg4*( (x-c3)^2/a3^2-(y-d3)^2/b3^2 )=0,x=c3-5..c3+5, y=d3-5..d3+5, grid=[81,81], scaling=constrained):
end if;
end proc:*)(*displayGraphs:=proc()
global choice;
Set(PL1=pl[choice[1]]);
Set(PL2=pl[choice[2]]);
Set(PL3=pl[choice[3]]);
Set(PL4=pl[choice[4]]);
end proc:*)(*graphHint:=proc()
if quadtype=1 then
Set(hintBox="Pay attention to the center.");
elif quadtype=2 then
Set(hintBox="Pay attention to the center and which is the major axis.");
elif quadtype=3 then
Set(hintBox="Pay attention to the center and where it opens.");
elif quadtype=4 then
Set(hintBox="Pay attention to the center and where it opens.");
elif quadtype=5 then
Set(hintBox="Pay attention to the center.");
end if;
end proc:*)
(*graphCheck:=proc()
global ans;
Set(graphReply="Incorrect", background=red);
Set(hintBox="Try again, you can do it!");
if Get(RP1) and ans=1 then
Set(graphReply="Correct!");
Set(hintBox="Good work! Now try a new equation!");
elif Get(RP2) and ans=2 then
Set(graphReply="Correct!");
Set(hintBox="Good work! Now try a new equation!");
elif Get(RP3) and ans=3 then
Set(graphReply="Correct!");
Set(hintBox="Good work! Now try a new equation!");
elif Get(RP4) and ans=4 then
Set(graphReply="Correct!");
Set(hintBox="Good work! Now try a new equation!");
end if;
end proc:*)
(*
graphShow:=proc()
global ans;
Set(graphReply="Shown");
if ans=1 then
Set(RP1=true);
elif ans=2 then
Set(RP2=true);
elif ans=3 then
Set(RP3=true);
elif ans=4 then
Set(RP4=true);
end if;
Set(hintBox="Try another equation yourself.");
end proc:
*)(*
BoxColumn( halign=none,border=true,
caption="Choose the Correct Graph:",
[
[ background=tan, border=true,
Plotter[PL1](plot0, width=150, height=150),
RadioButton[RP1]("Plot 1", value=false, group=BG1,
background=tan, foreground=black)
],
[ background=tan, border=true,
Plotter[PL2](plot0, width=150, height=150),
RadioButton[RP2]("Plot 2", value=false, group=BG1,
background=tan, foreground=black)
],
[ background=tan, border=true,
Plotter[PL3](plot0, width=150, height=150),
RadioButton[RP3]("Plot 3", value=false, group=BG1,
background=tan, foreground=black)
],
[ background=tan, border=true,
Plotter[PL4](plot0, width=150, height=150),
RadioButton[RP4]("Plot 4", value=false, group=BG1,
background=tan, foreground=black)
]
],
[ halign=none,
HorizontalGlue(),
Button("Hint", Evaluate(function = "graphHint"), background="Orange"),
Button("Check", Evaluate(function = "graphCheck"), background=green),
TextField[graphReply](width=10, editable=false, background=white),
Button("Show", Evaluate(function = "graphShow"), background=yellow),
HorizontalGlue()
]
),
*)QuadSections:=Maplet(onstartup = RunWindow(MAIN),
Window[MAIN](title="Identifying Quadratic Surfaces from Equations",
[ valign=none, inset=0, spacing=0,
[ halign=none,
Button("New Equation", Evaluate(function = "ask"), background=magenta),
HorizontalGlue(),
BoxRow( halign=none, border=true,
caption="Identify the Quadratic Surface and Graph of the Equation:",
HorizontalGlue(),
TextField[unsolvedEq](width=40, editable=false, background=white),
HorizontalGlue()
),
HorizontalGlue(),
Button("Quit", Shutdown(), background=pink)
],
[ halign=none,border=true,
caption="Complete the square and put the equation into standard form:",
TextField[compSq](width=30, background=cyan),
HorizontalGlue(),
Button("Hint", Evaluate(function = "compSqHint"), background="Orange"),
Button("Check", Evaluate(function = "compSqCheck"), background=green),
TextField[compSqReply](width=10, editable=false, background=white),
Button("Show", Evaluate(function = "compSqShow"), background=yellow)
],
[ halign=none,border=true,
caption="Identify the Quadratic Surface:",
DropDownBox[idQuad](background=cyan, width=210,
(*["Select", "Sphere", "Ellipsoid", "Hyperboloid of 1 Sheet", "Hyperboloid of 2 Sheets ",
"Cone", "Elliptic Paraboloid", "Hyperbolic Paraboloid",
"Elliptic Cylinder", "Hyperbolic Cylinder", "Parabolic Cylinder"]*)
["Select", "Sphere", "Ellipsoid", "Hyperboloid of 1 Sheet", "Hyperboloid of 2 Sheets ",
"Cone", "Elliptic Paraboloid", "Hyperbolic Paraboloid"]
),
HorizontalGlue(),
Button("Hint", Evaluate(function = "idQuadHint"), background="Orange"),
Button("Check", Evaluate(function = "idQuadCheck"), background=green),
TextField[idQuadReply](width=10, editable=false, background=white),
Button("Show", Evaluate(function = "idQuadShow"), background=yellow)
],
[
TextField[hintBox](width=60, background=white)
],
[ halign=none,
"Instructor: Philip Yasskin",
HorizontalGlue(),
"Programmers: Tyler Buffington & Kyle Baylis",
HorizontalGlue(),
"Copyright 2012, P. Yasskin"
]
]
),
ButtonGroup[BG1]()
):Maplets[Display]( QuadSections );