VectorValuedFunctions

From WeBWorK_wiki
Revision as of 19:03, 4 March 2010 by Pearson (talk | contribs) (New page: <h2>Vector Valued Functions as Answers</h2> <!-- Header for these sections -- no modification needed --> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> <em>T...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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: To do ..(what you are doing)........., we don't have to change the tagging and documentation section of the problem file. In the initialization section, we need to include the macros file -------.pl.

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

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

Setup: We specify that the Context should be ......, and define the answer to be a formula.

Notes: on using this and related Contexts.

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.  Let x, y, and z be measured in cm, and
t in seconds.
$BR
$BR
(a) Find any vector parametric equation for the 
line through points \( P \) and \( Q \).
\( L(t) = \) \{ ans_rule(40) \}
$BR
$BR
(b) Find a 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;

$T = Formula("$speed * t / norm($V)");
$L = $P + $T * $V;

ANS( ParametricLine("$L")->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; }

}

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

ENDDOCUMENT();

Answer Evaluation:

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

Problem Techniques Index


  • POD documentation:
  • PG macro: