Angles of a Triangle using Dot ProductsEmily Olmos & Rachel SternbergMath 151 Honors Section 202Fall 2013Instructor: Philip YasskinSerious
1) Your first 4 hints all have wrong formulas. The components are mixed up. Fixed2) You have 2 versions of the calculator proc. You are calling the second one, the one with a capital C.It does not work because it does not know what CalcExact is.In Calculator, CalcExact is a global variable which should be true if you want exact answers and false if you want decimal answers.In calculator, CalcExact is a parameter. So you need to call it with an argument of true or false.I recommend calculator(false) to check for decimal values. However your checktheta proc does not work for decimal values. Both fixed.3) Your checkAB and checkAC do not check the magnitude. It says correct no matter what you put there. Fixed.
Not serious
You need a header in the worksheet and a footer in the Maplet giving your names etc.
When you click New Problem, you also need to clear out the reply boxes and calculator boxes.
Your hints should have words as well as sentences. Not fixed.
restart:with(Maplets[Tools]):
with(Maplets[Elements]):
StartEngine();
randomize():rand5:=rand(-5..5):ask:=proc()
global AB,ABmag,AC,ACmag,Dot,costheta,theta;
local a1,a2,b1,b2,c1,c2;
a1:=rand5();
a2:=rand5();
b1:=rand5();
b2:=rand5();
c1:=rand5();
c2:=rand5();
AB:=[b1-a1,b2-a2];
AC:=[c1-a1,c2-a2];
Dot:=AB[1]*AC[1]+AB[2]*AC[2];
while Dot=0 do
a1:=rand5();
a2:=rand5();
b1:=rand5();
b2:=rand5();
c1:=rand5();
c2:=rand5();
AB:=[b1-a1,b2-a2];
AC:=[c1-a1,c2-a2];
Dot:=AB[1]*AC[1]+AB[2]*AC[2];
end do;
ABmag:=sqrt( (b1-a1)^2 + (b2-a2)^2 );
ACmag:=sqrt( (c1-a1)^2 + (c2-a2)^2 );
costheta:=Dot/( ABmag*ACmag );
theta:=evalf(arccos( costheta ));
Set(question=sprintf(
"Find the angle at A of the triangle with vertices\134n A=(%a,%a) B=(%a,%a) C=(%a,%a).", a1,a2,b1,b2,c1,c2));
Set(TFAB="");
Set(TFABmag="");
Set(MRAB="");
Set(TFAC="");
Set(TFACmag="");
Set(MRAC="");
Set(TFDot="");
Set(MRDot="");
Set(TFcostheta="");
Set(MRcostheta="");
Set(TFtheta="");
Set(MRtheta="");
Set(reply="");
Set(CalcIn="");
Set(CalcOut="");
end proc:showAB:=proc()
global AB,ABmag,AC,ACmag,Dot,costheta,theta;
Set(TFAB=AB);
Set(TFABmag=ABmag);
end proc:showAC:=proc()
global AB,ABmag,AC,ACmag,Dot,costheta,theta;
Set(TFAC=AC);
Set(TFACmag=ACmag);
end proc:showDot:=proc()
global AB,ABmag,AC,ACmag,Dot,costheta,theta;
Set(TFDot=Dot);
end proc:showcostheta:=proc()
global AB,ABmag,AC,ACmag,Dot,costheta,theta;
Set(TFcostheta=costheta);
end proc:showtheta:=proc()
global AB,ABmag,AC,ACmag,Dot,costheta,theta;
Set(TFtheta=theta);
end proc:checkAB:=proc()
global AB,ABmag,AC,ACmag,Dot,costheta,theta;
local userAB, userABmag;
userAB:=Get('TFAB'::anything, corrections=true, update=true):
userABmag:=Get('TFABmag'::anything, corrections=true, update=true):
if userAB=AB and simplify(userABmag-ABmag)=0 then
Set('MRAB'="Correct")
else
Set('MRAB'="Incorrect")
end if;
end proc:checkAC:=proc()
global AB,ABmag,AC,ACmag,Dot,costheta,theta;
local userAC, userACmag;
userAC:=Get('TFAC'::anything, corrections=true, update=true):
userACmag:=Get('TFACmag'::anything, corrections=true, update=true):
if userAC=AC and simplify(userACmag-ACmag)=0 then
Set('MRAC'="Correct")
else
Set('MRAC'="Incorrect")
end if;
end proc:checkDot:=proc()
global AB,ABmag,AC,ACmag,Dot,costheta,theta;
local userDot;
userDot:=Get('TFDot'::anything, corrections=true, update=true):
if userDot=Dot then
Set('MRDot'="Correct")
else
Set('MRDot'="Incorrect")
end if;
end proc:checkcostheta:=proc()
global AB,ABmag,AC,ACmag,Dot,costheta,theta;
local usercostheta;
usercostheta:=Get('TFcostheta'::anything, corrections=true, update=true):
if usercostheta=costheta then
Set('MRcostheta'="Correct")
else
Set('MRcostheta'="Incorrect")
end if;
end proc:checktheta:=proc()
global AB,ABmag,AC,ACmag,Dot,costheta,theta;
local usertheta;
usertheta:=Get('TFtheta'::anything, corrections=true, update=true):
if abs(evalf(usertheta-theta))<=.001*theta then
Set('MRtheta'="Correct")
else
Set('MRtheta'="Incorrect")
end if;
end proc:hintAB:=proc()
Set(reply=
" AB=[B1-A1,B2-A2] |AB|=sqrt((B1-A1)^2+(B2-A2)^2)");
end proc:hintAC:=proc()
Set(reply=
" AC=[C1-A1,C2-A2] |AC|=sqrt((C1-A1)^2+(C2-A2)^2)");
end proc:hintDot:=proc()
Set(reply=
" AB.AC = AB1*AC1 + AB2*AC2");
end proc:hintcostheta:=proc()
Set(reply=
" AB.AC/(|AB|*|AC|)");
end proc:hinttheta:=proc()
Set(reply=
" arccos(costheta)");
end proc:calculator:=proc(CalcExact)
local calc;
options `Copyright 2005-13, Philip B. Yasskin and Douglas Meade, Maplets for Calculus`;
if Get(CalcIn)="" then
return;
end if;
if CalcExact then
calc:=simplify(Get(CalcIn::realcons, corrections=true, update=true)):
else
calc:=evalf(Get(CalcIn::realcons, corrections=true, update=true)):
end if;
Set(CalcOut=calc):
end proc:Findangleswithdotproducts:=Maplet(onstartup = RunWindow(MAIN),
Window[MAIN](title= "Angles of a Triangle using Dot Products",
[ valign=none, inset=0, spacing=0,
[ halign=none,
Button("New Triangle", Evaluate(function = "ask"), background=magenta),
HorizontalGlue(),
TextBox[question](width=50, height=2, editable=false, background=white),
HorizontalGlue(),
Button("Quit", Shutdown(), background=pink)
],
BoxColumn( valign=none, inset=0, spacing=0, border=true,
caption="Step 1: Find the side vectors and their magnitudes:",
[ halign=none,
"AB =",
TextField[TFAB](width=15),
"|AB| =",
TextField[TFABmag](width=10),
HorizontalGlue(),
Button[BHtAB]("Hint", Evaluate(function= "hintAB"), background=Orange),
Button[BCkAB]("Check", Evaluate(function = "checkAB"), background=green),
TextField[MRAB](width=10),
Button[BShAB]("Show", Evaluate(function = "showAB"), background=yellow)
],
[ halign=none,
"AC =",
TextField[TFAC](width=15),
"|AC| =",
TextField[TFACmag](width=10),
HorizontalGlue(),
Button[BHtAC]("Hint", Evaluate(function= "hintAC"), background=Orange),
Button[BCkAC]("Check", Evaluate(function = "checkAC"), background=green),
TextField[MRAC](width=10),
Button[BShAC]("Show", Evaluate(function = "showAC"), background=yellow)
]
),
[ halign=none, border=true,
caption="Step 2: Find the dot product:",
"AB.AC= ",
TextField[TFDot](width=10),
HorizontalGlue(),
Button("Hint", Evaluate(function= "hintDot"), background=Orange),
Button("Check", Evaluate(function = "checkDot"), background=green),
TextField[MRDot](width=10),
Button("Show", Evaluate(function = "showDot"), background=yellow)
],
[ halign=none, border=true,
caption="Step 3: Find cos(theta):",
"cos(theta)= ",
TextField[TFcostheta](width=20),
HorizontalGlue(),
Button("Hint", Evaluate(function= "hintcostheta"), background=Orange),
Button("Check", Evaluate(function = "checkcostheta"), background=green),
TextField[MRcostheta](width=10),
Button("Show", Evaluate(function = "showcostheta"), background=yellow)
],
[ halign=none, border=true,
caption="Step 4: Find the angle (to within 0.1%):",
"theta= ",
TextField[TFtheta](width=15),
"radians",
HorizontalGlue(),
Button("Hint", Evaluate(function= "hinttheta"), background=Orange),
Button("Check", Evaluate(function = "checktheta"), background=green),
TextField[MRtheta](width=10),
Button("Show", Evaluate(function = "showtheta"), background=yellow)
],
[ halign=none,
TextField[reply](width=50, editable=false, background=white)
],
[ halign=none, border=true, background=tan,
caption=Calculator,
Formula,
TextField[CalcIn](width=40, background=turquoise),
HorizontalGlue(),
Button[BCalc](Calculate, Evaluate(function="calculator(false)"),
background=green),
TextField[CalcOut](width=10, editable=false, background=white)
],
[ halign=none, inset=0, spacing=0,
"Instructor: Philip Yasskin",
HorizontalGlue(),
"Programmers: Emily Olmos & Rachel Sternberg",
HorizontalGlue(),
"Copyright: Yasskin 2013"
]
]
)
):Maplets[Display]( Findangleswithdotproducts );