Difference between revisions of "VectorValuedFunctions"

From WeBWorK_wiki
Jump to navigation Jump to search
Line 47: Line 47:
 
<p>
 
<p>
 
<b>Initialization:</b>
 
<b>Initialization:</b>
To do ..(what you are doing)........., we don't have to change the
 
  +
The first three macros should always be loaded for questions whose answers are vector valued functions.
tagging and documentation section of the problem file.
 
  +
For the general vector parametric line (part (a) in the question below) we need to load <code>parserParametricLine.pl</code>, and for the specific vector parametric line (part (b) in the question below) we need to load <code>answerCustom.pl</code> since we will use a custom answer checker and want to have features like <code>showCoordinateHints</code> enabled.
In the initialization section, we need to include the macros file <code>-------.pl</code>.
 
 
</p>
 
</p>
 
</td>
 
</td>
Line 63: Line 62:
   
 
$P = non_zero_point3D();
 
$P = non_zero_point3D();
$V = non_zero_vector3D();
+
$disp = non_zero_vector3D();
$Q = Point($P + $V);
+
$Q = Point($P + $disp);
 
$speed = random(3,9,1);
 
$speed = random(3,9,1);
 
</pre>
 
</pre>
Line 71: Line 70:
 
<p>
 
<p>
 
<b>Setup:</b>
 
<b>Setup:</b>
We specify that the Context should be <code>......</code>, and define the answer to be a formula.
 
  +
We randomize two points in three-dimensional space, P and Q, a displacement vector between them, and a speed to travel between them.
 
</p>
 
</p>
<p>
 
Notes: on using this and related Contexts.
 
</p>
 
 
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 90: Line 85:
 
when \( t = 0 \) and moves along a straight line
 
when \( t = 0 \) and moves along a straight line
 
toward \( Q = $Q \) at a speed of \( $speed \)
 
toward \( Q = $Q \) at a speed of \( $speed \)
cm/sec.
 
  +
cm/sec. Assume that x, y, and z are measured
  +
in cm. Do not enter units with your answers.
 
$BR
 
$BR
 
$BR
 
$BR
(a) Find any vector parametric equation for the
+
(a) Find a vector parametric equation for the
 
line through points \( P \) and \( Q \).
 
line through points \( P \) and \( Q \).
 
$BR
 
$BR
Line 99: Line 95:
 
$BR
 
$BR
 
$BR
 
$BR
(b) Find a vector parametric equation
+
(b) Find the vector parametric equation
 
for the position of the object.
 
for the position of the object.
 
$BR
 
$BR
Line 121: Line 117:
 
$showPartialCorrectAnswers = 1;
 
$showPartialCorrectAnswers = 1;
   
$T = Formula("$speed * t / norm($V)");
 
$L = $P + $T * $V;
 
   
ANS( ParametricLine("$L")->cmp() );
+
ANS( ParametricLine("$P + t * $disp")->cmp() );
   
   
Line 139: Line 133:
 
}
 
}
   
ANS( custom_cmp( $L, ~~&mycheck, showCoordinateHints=>1 ) );
 
  +
  +
#$T = Formula("$speed * t / norm($disp)");
  +
  +
$r = $P + $speed * t * $disp / norm($disp);
  +
  +
ANS( custom_cmp( $r, ~~&mycheck, showCoordinateHints=>1 ) );
   
 
ENDDOCUMENT();
 
ENDDOCUMENT();
Line 146: Line 145:
 
<p>
 
<p>
 
<b>Answer Evaluation:</b>
 
<b>Answer Evaluation:</b>
  +
The answer to part (a) can be any vector parametric line through the points P and Q, so we use <code>ParametricLine("$P + $T * $disp")</code> to allow student answers that use a different parametrization to be marked correct.
 
</p>
 
</p>
 
<p>
 
<p>

Revision as of 19:26, 4 March 2010

Vector Valued Functions as Answers


This shows the PG code to check student answers that are vectors whose components are formulas.

  • Example 1: Vector Parametric Lines


Example 1: Vector Parametric Lines

Problem Techniques Index

PG problem file Explanation
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserVectorUtils.pl",
"parserParametricLine.pl",
"answerCustom.pl",
"PGcourse.pl",
);
TEXT(beginproblem());

Initialization: The first three macros should always be loaded for questions whose answers are vector valued functions. For the general vector parametric line (part (a) in the question below) we need to load parserParametricLine.pl, and for the specific vector parametric line (part (b) in the question below) we need to load answerCustom.pl since we will use a custom answer checker and want to have features like showCoordinateHints enabled.

Context("Vector");
Context()->variables->are(t=>"Real");

$P = non_zero_point3D();
$disp = non_zero_vector3D();
$Q = Point($P + $disp);
$speed = random(3,9,1);

Setup: We randomize two points in three-dimensional space, P and Q, a displacement vector between them, and a speed to travel between them.

Context()->texStrings;
BEGIN_TEXT
A particle starts at the point \( P = $P \)
when \( t = 0 \) and moves along a straight line
toward \( Q = $Q \) at a speed of \( $speed \) 
cm/sec.  Assume that x, y, and z are measured
in cm.  Do not enter units with your answers.
$BR
$BR
(a) Find a vector parametric equation for the 
line through points \( P \) and \( Q \).
$BR
\( L(t) = \) \{ ans_rule(40) \}
$BR
$BR
(b) Find the vector parametric equation
for the position of the object.
$BR
\( \vec{r}(t) = \) \{ans_rule(40)\}
END_TEXT
Context()->normalStrings;

Main Text: The problem text section of the file is as we'd expect.

$showPartialCorrectAnswers = 1;


ANS( ParametricLine("$P + t * $disp")->cmp() );


sub mycheck {
  my ($correct, $student, $ansHash) = @_;

  if ( 
       ($correct . i == $student . i) && 
       ($correct . j == $student . j) && 
       ($correct . k == $student . k) 
     ) 
  { return 1; } else { return 0; }

}


#$T = Formula("$speed * t / norm($disp)");

$r = $P + $speed * t * $disp / norm($disp);

ANS( custom_cmp( $r, ~~&mycheck, showCoordinateHints=>1 ) );

ENDDOCUMENT();

Answer Evaluation: The answer to part (a) can be any vector parametric line through the points P and Q, so we use ParametricLine("$P + $T * $disp") to allow student answers that use a different parametrization to be marked correct.

For more on custom answer evaluators, see CustomAnswerCheckers and answerCustom.pl.html

Problem Techniques Index