Spacecurve1

From WeBWorK_wiki
Jump to navigation Jump to search
This article has been retained as a historical document. It is not up-to-date and the formatting may be lacking. Use the information herein with caution.

This problem has been replaced with a newer version of this problem

A Parametric Curve in Space

Click to enlarge

This PG code shows how to ask a parametric curve question with three answer blanks and use MultiAnswer to check the answer.


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();      

loadMacros(
  'PGstandard.pl',
  'MathObjects.pl',
  'parserMultiAnswer.pl',
  'PGML.pl',
  'PGcourse.pl'
);

TEXT(beginproblem());

Initialization: Since we will have multiple answer blanks that depend on each other, we need to use parserMultiAnswer.pl.

Context("Numeric");
Context()->variables->are(t=>"Real");
Context()->variables->set(t=>{limits=>[0,10]});

$a = random(-5,-2,1);
$x = Formula("$a * t**2");
$y = Formula("0");
$z = Formula("t");

$multians = MultiAnswer($x, $y, $z)->with(
  singleResult => 1,
  checker => sub {
      my ( $correct, $student, $self ) = @_;
      my ( $xstu, $ystu, $zstu ) = @{$student};
      return 0 unless $xstu->isFormula;
      if (($xstu==$a*$zstu**2) && ($ystu==0)) {
            return 1;
      } else {
            return 0;
      }
  }
);

Setup: We use singleResult => 1 since it doesn't make sense to say that x(t) is correct but z(t) is incorrect since they depend on one another. First, we check that the student hasn't fed us a bogus constant solution such as x=y=z=0 by requiring the x-coordinate to be a formula (not a constant) via return 0 unless $xstu->isFormula;. Then, we check that the student's answers satisfy the parametric equation.

BEGIN_PGML
Find a parametrization of the curve [` x = [$a] z^2 `]
in the [`xz`]-plane.  Use [` t `] as the
parameter for all of your answers.

- [` x(t) = `] [______________]{$multians}
- [` y(t) = `] [______________]{$multians}
- [` z(t) = `] [______________]{$multians}

[@ helpLink('formulas') @]*
END_PGML

Main Text: Notice that we use $multians in each answer blank because they results in the three answers are dependent on each other.

BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution:

Templates by Subject Area