Parametric equations: parametric curve in space
Download file: VectorParametricFunction.pg
DOCUMENT();
loadMacros(
'PGstandard.pl', 'PGML.pl',
'parserVectorUtils.pl', 'parserMultiAnswer.pl',
'PGcourse.pl'
);
Preamble
Although not necessary for the code demonstrated in this example, you might want to load parserVectorUtils.pl. It provides methods that are useful for vector problems.
The parserMultiAnswer.pl macro is used since the answers depend upon each other.
Context('Vector2D');
# Context('Vector'); # use for 3D vectors
Context()->variables->are(t => 'Real');
$a = random(2, 5);
Context()->variables->set(t => { limits => [ 0, $a ] });
$Q = Point($a, $a**2);
$multians = MultiAnswer(Vector("<t,t**2>"), 0, $a)->with(
singleResult => 1,
checker => sub {
my ($correct, $student, $self) = @_; # get the parameters
my ($f, $x1, $x2) = @$student; # extract student answers
if (($f . i)**2 == $f . j
&& $f->eval(t => $x1) == Vector("<0,0>")
&& $f->eval(t => $x2) == Vector("<$a,$a**2>"))
{
return 1;
} elsif (($f . i)**2 == $f . j
&& $f->eval(t => $x1) == Vector("<0,0>"))
{
$self->setMessage(3, 'Your right endpoint is not correct.');
return 0;
} elsif (($f . i)**2 == $f . j
&& $f->eval(t => $x2) == Vector("<$a,$a**2>"))
{
$self->setMessage(2, 'Your left endpoint is not correct.');
return 0;
} elsif (($f . i)**2 == $f . j) {
$self->setMessage(2, 'Your left endpoint is not correct.');
$self->setMessage(3, 'Your right endpoint is not correct.');
return 0;
} else {
return 0;
}
}
);
Setup
In the checker the vector-valued function that the student enters is
stored in $f. It is dotted with the standard basis vectors
i and j to obtain the x and
y components.
Note that if you need to differentiate the component functions in the
student answer, you will need to use a different method. Attempting to
compute ($f . i)->D('t') will generate errors since the
dot product does not get evaluated. See Parametric
Vector Function with Derivative for an example of how to extract
formulas from the components of the student answer, which can then be
differentiated.
Notice that feedback messages are provided regarding which endpoints are incorrect.
BEGIN_PGML
Find a vector parametric equation for the parabola [`y = x^2`] from the origin
to the point [`[$Q]`] using [`t`] as a parameter.
[`\vec{r}(t) =`] [_]{$multians}{10}
for [___]{$multians} [`\leq t \leq`] [___]{$multians}.
END_PGML
Statement
This is the problem statement in PGML.BEGIN_PGML_SOLUTION Solution explanation goes here. END_PGML_SOLUTION ENDDOCUMENT();
Solution
A solution should be provided here.