VectorValuedFunctions
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
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 |
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() ); # for checking a particular vector parametric line 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 + $T * $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 For more on custom answer evaluators, see CustomAnswerCheckers and answerCustom.pl.html |
- POD documentation: parserParametricLine.pl.html
- PG macro: parserParametricLine.pl
- POD documentation: answerCustom.pl.html
- PG macro: answerCustom.pl