Difference between revisions of "VectorParametric1"

From WeBWorK_wiki
Jump to navigation Jump to search
(Created page with '<h2>A Vector Parametric Curve in the Plane</h2> 300px|thumb|right|Click to enlarge <p style="background-color:#f9f9f9;border:black solid 1px;paddi…')
 
Line 5: Line 5:
 
This PG code shows how to ask students for a vector parametric curve through two points and allows them to specify the time interval.
 
This PG code shows how to ask students for a vector parametric curve through two points and allows them to specify the time interval.
 
</p>
 
</p>
* Download file: [[File:Filename1.txt]] (change the file extension from txt to pg when you save it)
+
* Download file: [[File:VectorParametric1.txt]] (change the file extension from txt to pg when you save it)
* File location in NPL: <code>FortLewis/Authoring/Templates/...</code>
+
* File location in NPL: <code>FortLewis/Authoring/Templates/Parametric/VectorParametric1.pg</code>
   
 
<br clear="all" />
 
<br clear="all" />
Line 45: Line 45:
 
"PGstandard.pl",
 
"PGstandard.pl",
 
"MathObjects.pl",
 
"MathObjects.pl",
"AnswerFormatHelp.pl",
+
"parserVectorUtils.pl",
  +
"parserMultiAnswer.pl",
 
);
 
);
   
Line 54: Line 54:
 
<p>
 
<p>
 
<b>Initialization:</b>
 
<b>Initialization:</b>
  +
Since it is a vector parametric curve, we will want vector utilities from <code>parserVectorUtils.pl</code>. Since we will need to check multiple answer blanks that depend upon each other, we use <code>parserMultiAnswer.pl</code>.
 
</p>
 
</p>
 
</td>
 
</td>
Line 64: Line 65:
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context("Numeric");
+
Context("Vector2D");
  +
#Context("Vector"); # for 3D vectors
  +
Context()->variables->are(t=>"Real");
  +
Context()->variables->set(t=>{limits=>[0,5]});
  +
Context()->flags->set( ijk=>0 );
   
$answer = Compute("1");
+
$a = random(2,5,1);
  +
$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; }
  +
  +
  +
}
  +
);
 
</pre>
 
</pre>
 
</td>
 
</td>
Line 72: Line 73:
 
<p>
 
<p>
 
<b>Setup:</b>
 
<b>Setup:</b>
  +
The student's vector-valued function is stored in <code>$f</code>. To get the x- and y-components of the students answer we dot it with the standard basis vectors using <code>$f . i</code> and <code>$f . j</code>. Note: If you want to differentiate the component functions in the student's answer, you'll need to use a different method as <code>($f . i)->D('t')</code> will generate errors since the dot product does not get evaluated. Another problem given in this section describes how to extract formulas from the components of the student's answer, which can then be differentiated. Notice that we have given the students helpful feedback messages about which endpoints are incorrect.
 
</p>
 
</p>
 
</td>
 
</td>
Line 83: Line 85:
 
Context()->texStrings;
 
Context()->texStrings;
 
BEGIN_TEXT
 
BEGIN_TEXT
Question text
 
  +
Find a vector parametric equation for the parabola
  +
\( y = x^2 \) from the origin to the point
  +
\( $Q \) using \( t \) as a parameter.
 
$BR
 
$BR
 
$BR
 
$BR
Answer =
 
  +
\( \vec{r}(t) = \)
\{ ans_rule(20) \}
+
\{$multians->ans_rule(20)\}
\{ AnswerFormatHelp("formulas") \}
+
for
  +
\{$multians->ans_rule(5)\}
  +
\( \leq t \leq \)
  +
\{$multians->ans_rule(5)\}
 
END_TEXT
 
END_TEXT
 
Context()->normalStrings;
 
Context()->normalStrings;
Line 106: Line 110:
 
$showPartialCorrectAnswers = 1;
 
$showPartialCorrectAnswers = 1;
   
ANS( $answer->cmp() );
+
ANS( $multians->cmp() );
 
</pre>
 
</pre>
 
<td style="background-color:#eeccff;padding:7px;">
 
<td style="background-color:#eeccff;padding:7px;">
Line 129: Line 133:
 
COMMENT('MathObject version.');
 
COMMENT('MathObject version.');
   
ENDDOCUMENT();
+
ENDDOCUMENT();
 
</pre>
 
</pre>
 
<td style="background-color:#ddddff;padding:7px;">
 
<td style="background-color:#ddddff;padding:7px;">

Revision as of 00:01, 10 December 2010

A Vector Parametric Curve in the Plane

Click to enlarge

This PG code shows how to ask students for a vector parametric curve through two points and allows them to specify the time interval.

  • Download file: File:VectorParametric1.txt (change the file extension from txt to pg when you save it)
  • File location in NPL: FortLewis/Authoring/Templates/Parametric/VectorParametric1.pg


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserVectorUtils.pl",
"parserMultiAnswer.pl",
);

TEXT(beginproblem());

Initialization: Since it is a vector parametric curve, we will want vector utilities from parserVectorUtils.pl. Since we will need to check multiple answer blanks that depend upon each other, we use parserMultiAnswer.pl.

Context("Vector2D");
#Context("Vector"); # for 3D vectors
Context()->variables->are(t=>"Real");
Context()->variables->set(t=>{limits=>[0,5]});
Context()->flags->set( ijk=>0 );

$a = random(2,5,1);
$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: The student's vector-valued function is stored in $f. To get the x- and y-components of the students answer we dot it with the standard basis vectors using $f . i and $f . j. Note: If you want to differentiate the component functions in the student's answer, you'll need to use a different method as ($f . i)->D('t') will generate errors since the dot product does not get evaluated. Another problem given in this section describes how to extract formulas from the components of the student's answer, which can then be differentiated. Notice that we have given the students helpful feedback messages about which endpoints are incorrect.

Context()->texStrings;
BEGIN_TEXT
Find a vector parametric equation for the parabola
\( y = x^2 \) from the origin to the point 
\( $Q \) using \( t \) as a parameter.
$BR
$BR
\( \vec{r}(t) = \) 
\{$multians->ans_rule(20)\} 
for 
\{$multians->ans_rule(5)\} 
\( \leq t \leq \) 
\{$multians->ans_rule(5)\}
END_TEXT
Context()->normalStrings;

Main Text:

$showPartialCorrectAnswers = 1;

ANS( $multians->cmp() );

Answer Evaluation:

Context()->texStrings;
BEGIN_SOLUTION
${PAR}SOLUTION:${PAR}
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version.');

ENDDOCUMENT(); 

Solution:

Templates by Subject Area