## DBsubject('Calculus') ## DBchapter('Vector Geometry') ## DBsection('Dot Product and the Angle Between Two Vectors') ## KEYWORDS('calculus', 'parametric', 'vector', 'dot product', 'scalar product', 'angle', 'projection', 'proj') ## TitleText1('Calculus: Early Transcendentals') ## EditionText1('2') ## AuthorText1('Rogawski') ## Section1('12.3') ## Problem1('13') ## Author('Christopher Sira') ## Institution('W.H.Freeman') DOCUMENT(); loadMacros("PG.pl","PGbasicmacros.pl","PGanswermacros.pl"); loadMacros("PGchoicemacros.pl"); loadMacros("Parser.pl"); loadMacros("freemanMacros.pl"); \$context = Context("Vector"); Context()->texStrings; sub vdot { my(\$temp) = 0; for (\$i = 0; \$i < 3; \$i++) { \$temp = \$temp + \$_[\$i] * \$_[\$i + 3]; } return \$temp } sub vlen { return sqrt(\$_[0]**2 + \$_[1]**2 + \$_[2]**2); } sub vcos { my(\$dot) = vdot(@_); return \$dot / (vlen(\$_[0], \$_[1], \$_[2]) * vlen(\$_[3], \$_[4], \$_[5])); } sub vang { return Formula("arccos(x)")->eval(x=>vcos(@_)); } # projection of u onto v (first onto second) sub vproj { my(@temp) = (\$_[3], \$_[4], \$_[5]); my(\$temp2) = vdot(@_); \$temp2 = \$temp2 / vdot(\$_[3], \$_[4], \$_[5], \$_[3], \$_[4], \$_[5]); \$temp[0] *= \$temp2; \$temp[1] *= \$temp2; \$temp[2] *= \$temp2; return @temp; } # perpendicular component of u onto v (first onto second) sub vperp { my(@temp) = vproj(@_); \$temp[0] = -1 * \$temp[0] + \$_[0]; \$temp[1] = -1 * \$temp[1] + \$_[1]; \$temp[2] = -1 * \$temp[2] + \$_[2]; return @temp; } \$iv0 = 1; \$iv1 = 0; \$iv2 = 0; \$jv0 = 0; \$jv1 = 1; \$jv2 = 0; \$kv0 = 0; \$kv1 = 0; \$kv2 = 1; @iva = (\$iv0, \$iv1, \$iv2); @jva = (\$jv0, \$jv1, \$jv2); @kva = (\$kv0, \$kv1, \$kv2); \$iv = Vector(@iva); \$jv = Vector(@jva); \$kv = Vector(@kva); \$v0 = Real(random(-10, 10, 1)); \$v1 = Real(random(-10, 10, 1)); \$v2 = Real(random(-10, 10, 1)); # make unit vector #\$v0 = \$v0 / vlen(\$v0, \$v1, \$v2); #\$v1 = \$v1 / vlen(\$v0, \$v1, \$v2); #\$v2 = \$v2 / vlen(\$v0, \$v1, \$v2); \$w0 = Real(random(1, 10, 1)); \$w1 = Real(random(1, 10, 1)); \$w2 = Real(random(1, 10, 1)); # make unit vector #\$w0 = \$v0 / vlen(\$v0, \$v1, \$v2); #\$w1 = \$v1 / vlen(\$v0, \$v1, \$v2); #\$w2 = \$v2 / vlen(\$v0, \$v1, \$v2); @va = (\$v0, \$v1, \$v2); @wa = (\$w0, \$w1, \$w2); \$v = Vector(\$v0, \$v1, \$v2); \$w = Vector(\$w0, \$w1, \$w2); \$mc = new_multiple_choice(); \$ans = "obtuse"; \$temp = "<"; \$dot = vdot(@va, @wa); if (\$dot == 0) { \$mc->qa("The angle between \( \$v \) and \( \$w \) is:", "orthogonal"); \$mc->extra("acute", "obtuse"); \$ans = "orthogonal"; \$temp = "="; } else { if (\$dot < 0) { \$mc->qa("The angle between \( \$v \) and \( \$w \) is:", "obtuse"); \$mc->extra("acute", "orthogonal"); \$ans = "obtuse"; \$temp = "<"; } else { \$mc->qa("The angle between \( \$v \) and \( \$w \) is:", "acute"); \$mc->extra("obtuse", "orthogonal"); \$ans = "acute"; \$temp = ">"; } } Context()->texStrings; BEGIN_TEXT \{ beginproblem() \} \{ textbook_ref_exact("Rogawski ET 2e", "12.3","13") \} \{\$mc->print_q\} \$PAR \{\$mc->print_a\} END_TEXT Context()->normalStrings; ANS(str_cmp(\$mc->correct_ans)); Context()->texStrings; SOLUTION(EV3(<<'END_SOLUTION')); \$PAR \$SOL The type of angle between \( v \) and \( w \) can be determined by taking the dot product. \$PAR \( v \cdotp w = 0 \) only when \( v \) and \( w \) are orthogonal. \$PAR \( v \cdotp w < 0 \) only when the angle between \( v \) and \( w \) is obtuse. \$PAR \( v \cdotp w > 0 \) only when the angle between \( v \) and \( w \) is acute. \$PAR Now, \( \$v \cdotp \$w = \$dot \$temp 0 \), so the angle between \( v \) and \( w \) is \${ans}. END_SOLUTION ENDDOCUMENT();