Difference between revisions of "VectorValuedFunctions"

From WeBWorK_wiki
Jump to navigation Jump to search
(added historical tag and gave updated problem links)
 
(23 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  +
{{historical}}
  +
  +
<p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/VectorCalc/VectorParametricLine.html a parametric line problem], [https://openwebwork.github.io/pg-docs/sample-problems/VectorCalc/VectorLineSegment1.html a vector line segment problem] and
  +
[https://openwebwork.github.io/pg-docs/sample-problems/VectorCalc/VectorLineSegment2.html another vector line segment problem] </p>
 
<h2>Vector Valued Functions as Answers</h2>
 
<h2>Vector Valued Functions as Answers</h2>
   
Line 7: Line 11:
 
</p>
 
</p>
 
<ul>
 
<ul>
<li>Example 1: Vector Parametric Lines</li>
 
  +
<li><b>Example 1:</b> A vector parametric line where the student chooses the parametrization</li>
  +
<li><b>Example 2:</b> A vector parametric line segment where the student chooses the parametrization and the starting and ending times</li>
  +
<li><b>Example 3:</b> A vector parametric line segment where the student must enter a particular parametrization and use particular starting and ending times</li>
 
</ul>
 
</ul>
  +
   
   
   
 
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
 
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
<em><b>Example 1:</b> Vector Parametric Lines</em>
+
<em><b>Example 1:</b> A vector parametric line where the student chooses the parametrization</em>
 
</p>
 
</p>
   
Line 38: Line 45:
 
"parserVectorUtils.pl",
 
"parserVectorUtils.pl",
 
"parserParametricLine.pl",
 
"parserParametricLine.pl",
"answerCustom.pl",
 
 
"PGcourse.pl",
 
"PGcourse.pl",
 
);
 
);
Line 47: Line 53:
 
<p>
 
<p>
 
<b>Initialization:</b>
 
<b>Initialization:</b>
To do ..(what you are doing)........., we don't have to change the
 
  +
The first three macros should always be loaded for questions whose answers are vector valued functions.
tagging and documentation section of the problem file.
 
  +
For the general vector parametric line we need to load <code>parserParametricLine.pl</code>.
In the initialization section, we need to include the macros file <code>-------.pl</code>.
 
 
</p>
 
</p>
 
</td>
 
</td>
Line 63: Line 68:
   
 
$P = non_zero_point3D();
 
$P = non_zero_point3D();
$V = non_zero_vector3D();
+
$disp = non_zero_vector3D();
$Q = Point($P + $V);
+
$Q = Point($P + $disp);
$speed = random(3,9,1);
 
 
</pre>
 
</pre>
 
</td>
 
</td>
Line 70: Line 75:
 
<p>
 
<p>
 
<b>Setup:</b>
 
<b>Setup:</b>
We specify that the Context should be <code>......</code>, and define the answer to be a formula.
 
  +
We randomize two points in three-dimensional space, P and Q, a displacement vector between them, and a speed to travel between them.
 
</p>
 
</p>
  +
</td>
  +
</tr>
  +
  +
<!-- Question text section -->
  +
  +
<tr valign="top">
  +
<td style="background-color:#ffdddd;border:black 1px dashed;">
  +
<pre>
  +
Context()->texStrings;
  +
BEGIN_TEXT
  +
Find a vector parametric equation for the
  +
line through points \( P = $P \) and \( Q = $Q \).
  +
$BR
  +
\( \vec{r}(t) = \) \{ ans_rule(40) \}
  +
END_TEXT
  +
Context()->normalStrings;
  +
</pre>
  +
<td style="background-color:#ffcccc;padding:7px;">
 
<p>
 
<p>
Notes: on using this and related Contexts.
 
  +
<b>Main Text:</b>
  +
The problem text section of the file is as we'd expect.
 
</p>
 
</p>
  +
</td>
  +
</tr>
   
  +
<!-- Answer section -->
  +
  +
<tr valign="top">
  +
<td style="background-color:#eeddff;border:black 1px dashed;">
  +
<pre>
  +
$showPartialCorrectAnswers = 1;
  +
  +
ANS( ParametricLine("$P + t * $disp")->cmp() );
  +
  +
ENDDOCUMENT();
  +
</pre>
  +
<td style="background-color:#eeccff;padding:7px;">
  +
<p>
  +
<b>Answer Evaluation:</b>
  +
The answer can be any vector parametric line through the points P and Q, so we use <code>ParametricLine("$P + t * $disp")</code> provided by <code>parserParametricLine.pl</code> to allow student answers that use a different parametrization, such as <code>$Q - 2*t * $disp</code>, to be marked correct.
  +
</p>
  +
</td>
  +
</tr>
  +
</table>
  +
  +
<p style="text-align:center;">
  +
[[IndexOfProblemTechniques|Problem Techniques Index]]
  +
</p>
  +
  +
[[Category:Problem Techniques]]
  +
  +
  +
  +
  +
  +
  +
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
  +
<em><b>Example 2:</b> A vector parametric line segment where the student chooses the parametrization and the starting and ending times</em>
  +
</p>
  +
  +
<p style="text-align:center;">
  +
[[IndexOfProblemTechniques|Problem Techniques Index]]
  +
</p>
  +
  +
<table cellspacing="0" cellpadding="2" border="0">
  +
  +
<tr valign="top">
  +
<th> PG problem file </th>
  +
<th> Explanation </th>
  +
</tr>
  +
  +
<!-- Load specialized macro files section -->
  +
  +
<tr valign="top">
  +
<td style="background-color:#ddffdd;border:black 1px dashed;">
  +
<pre>
  +
DOCUMENT();
  +
loadMacros(
  +
"PGstandard.pl",
  +
"MathObjects.pl",
  +
"parserVectorUtils.pl",
  +
"parserParametricLine.pl",
  +
"parserMultiAnswer.pl",
  +
"PGcourse.pl",
  +
);
  +
TEXT(beginproblem());
  +
</pre>
  +
</td>
  +
<td style="background-color:#ccffcc;padding:7px;">
  +
<p>
  +
<b>Initialization:</b>
  +
The first three macros should always be loaded for questions whose answers are vector valued functions.
  +
We need to load <code>parserParametricLine.pl</code> and <code>parserMultiAnswer.pl</code> since we will want to evaluate the student's answer at the starting and ending times provided by the student.
  +
</p>
  +
</td>
  +
</tr>
  +
  +
<!-- Setup section -->
  +
  +
<tr valign="top">
  +
<td style="background-color:#ffffdd;border:black 1px dashed;">
  +
<pre>
  +
Context("Vector");
  +
Context()->variables->are(t=>"Real");
  +
  +
$P = Point(4,0);
  +
$Q = Point(0,2);
  +
$V = Vector(-4,2);
  +
  +
$t = Formula("t");
  +
$line = Vector("$P + $t * $V");
  +
  +
$multians = MultiAnswer( $line, Real("0"), Real("1") )->with(
  +
singleResult => 0,
  +
checker => sub {
  +
my ( $correct, $student, $ansHash ) = @_;
  +
my ( $linestu, $astu, $bstu ) = @{$student};
  +
my ( $linecor, $acor, $bcor ) = @{$correct};
  +
  +
if ( (ParametricLine("$line") == $linestu) &&
  +
($linestu->eval(t=>$astu) == $line->eval(t=>"0")) &&
  +
($linestu->eval(t=>$bstu) == $line->eval(t=>"1")) )
  +
{
  +
return [1,1,1];
  +
  +
} elsif ( (ParametricLine("$line") == $linestu) &&
  +
($linestu->eval(t=>$astu) == $line->eval(t=>"0")) )
  +
{
  +
return [1,1,0];
  +
  +
} elsif ( (ParametricLine("$line") == $linestu) &&
  +
($linestu->eval(t=>$bstu) == $line->eval(t=>"1")) )
  +
{
  +
return [1,0,1];
  +
  +
} elsif ( (ParametricLine("$line") == $linestu) )
  +
{
  +
return [1,0,0];
  +
  +
} else {
  +
return [0,0,0];
  +
}
  +
  +
}
  +
);
  +
</pre>
  +
</td>
  +
<td style="background-color:#ffffcc;padding:7px;">
  +
<p>
  +
<b>Setup:</b>
  +
We create a MutiAnswer answer checker that will evaluate the students vector parametric equation at the starting and ending times provided by the student. For example, both of the student answers <code>(4,0) + t<-4,2></code> for t between 0 and 1, and <code>(4,0) + t<-2,1></code> for t between 0 and 2 will be marked correct.
  +
</p>
  +
</td>
  +
</tr>
  +
  +
<!-- Question text section -->
  +
  +
<tr valign="top">
  +
<td style="background-color:#ffdddd;border:black 1px dashed;">
  +
<pre>
  +
Context()->texStrings;
  +
BEGIN_TEXT
  +
Find a vector parametric equation for the line
  +
segment from the point \(P = $P\)
  +
to \(Q = $Q\).
  +
$BR
  +
\( \vec{r}(t) = \)
  +
\{ $multians->ans_rule(40 )\}
  +
for
  +
\{ $multians->ans_rule(5) \}
  +
\( \leq t \leq \)
  +
\{ $multians->ans_rule(5) \}
  +
END_TEXT
  +
Context()->normalStrings;
  +
</pre>
  +
<td style="background-color:#ffcccc;padding:7px;">
  +
<p>
  +
<b>Main Text:</b>
  +
The problem text section of the file is as we'd expect.
  +
</p>
  +
</td>
  +
</tr>
  +
  +
<!-- Answer section -->
  +
  +
<tr valign="top">
  +
<td style="background-color:#eeddff;border:black 1px dashed;">
  +
<pre>
  +
$showPartialCorrectAnswers = 1;
  +
  +
ANS( $multians->cmp() );
  +
  +
ENDDOCUMENT();
  +
</pre>
  +
<td style="background-color:#eeccff;padding:7px;">
  +
<p>
  +
<b>Answer Evaluation:</b>
  +
This part is easy since we defined <code>$multians</code> above.
  +
</p>
  +
</td>
  +
</tr>
  +
</table>
  +
  +
<p style="text-align:center;">
  +
[[IndexOfProblemTechniques|Problem Techniques Index]]
  +
</p>
  +
  +
[[Category:Problem Techniques]]
  +
  +
  +
  +
  +
  +
  +
  +
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
  +
<em><b>Example 3:</b> A vector parametric line segment where the student must enter a particular parametrization and use particular starting and ending times</em>
  +
</p>
  +
  +
<p style="text-align:center;">
  +
[[IndexOfProblemTechniques|Problem Techniques Index]]
  +
</p>
  +
  +
<table cellspacing="0" cellpadding="2" border="0">
  +
  +
<tr valign="top">
  +
<th> PG problem file </th>
  +
<th> Explanation </th>
  +
</tr>
  +
  +
<!-- Load specialized macro files section -->
  +
  +
<tr valign="top">
  +
<td style="background-color:#ddffdd;border:black 1px dashed;">
  +
<pre>
  +
DOCUMENT();
  +
loadMacros(
  +
"PGstandard.pl",
  +
"MathObjects.pl",
  +
"parserVectorUtils.pl",
  +
"PGcourse.pl",
  +
);
  +
TEXT(beginproblem());
  +
</pre>
  +
</td>
  +
<td style="background-color:#ccffcc;padding:7px;">
  +
<p>
  +
<b>Initialization:</b>
  +
The first three macros should always be loaded for questions whose answers are vector valued functions.
  +
For the specific vector parametric line we will use a custom answer checker.
  +
</p>
  +
</td>
  +
</tr>
  +
  +
<!-- Setup section -->
  +
  +
<tr valign="top">
  +
<td style="background-color:#ffffdd;border:black 1px dashed;">
  +
<pre>
  +
Context("Vector");
  +
Context()->variables->are(t=>"Real");
  +
  +
$P = non_zero_point3D();
  +
$disp = non_zero_vector3D();
  +
$Q = Point($P + $disp);
  +
$speed = random(3,9,1);
  +
</pre>
  +
</td>
  +
<td style="background-color:#ffffcc;padding:7px;">
  +
<p>
  +
<b>Setup:</b>
  +
We randomize two points in three-dimensional space, P and Q, a displacement vector between them, and a speed to travel between them.
  +
</p>
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 89: Line 363:
 
when \( t = 0 \) and moves along a straight line
 
when \( t = 0 \) and moves along a straight line
 
toward \( Q = $Q \) at a speed of \( $speed \)
 
toward \( Q = $Q \) at a speed of \( $speed \)
cm/sec.
 
  +
cm/sec. Assume that x, y, and z are measured
$BR
 
  +
in cm. Do not enter units with your answers.
$BR
 
(a) Find any vector parametric equation for the
 
line through points \( P \) and \( Q \).
 
$BR
 
\( L(t) = \) \{ ans_rule(40) \}
 
 
$BR
 
$BR
 
$BR
 
$BR
(b) Find a vector parametric equation
+
Find the vector parametric equation
 
for the position of the object.
 
for the position of the object.
 
$BR
 
$BR
Line 120: Line 389:
 
$showPartialCorrectAnswers = 1;
 
$showPartialCorrectAnswers = 1;
   
$T = Formula("$speed * t / norm($V)");
 
  +
# for checking a particular vector parametric line
$L = $P + $T * $V;
 
 
ANS( ParametricLine("$L")->cmp() );
 
 
 
 
sub mycheck {
 
sub mycheck {
 
my ($correct, $student, $ansHash) = @_;
 
my ($correct, $student, $ansHash) = @_;
Line 135: Line 399:
 
)
 
)
 
{ return 1; } else { return 0; }
 
{ return 1; } else { return 0; }
 
 
}
 
}
   
ANS( custom_cmp( $L, ~~&mycheck, showCoordinateHints=>1 ) );
 
  +
$T = Formula("$speed * t / norm($disp)");
  +
$r = $P + $T * $disp;
  +
  +
ANS( $answer->cmp( checker=>~~&mycheck ) );
   
 
ENDDOCUMENT();
 
ENDDOCUMENT();
Line 145: Line 411:
 
<p>
 
<p>
 
<b>Answer Evaluation:</b>
 
<b>Answer Evaluation:</b>
  +
There is only one vector parametric equation that describes the position of the object subject to the given conditions, so we want only one answer to be marked correct. We create a custom answer checker <code>mycheck</code>, which is a subroutine that verifies that the student's answer agrees with the correct answer in each component by taking the dot product with the each of the vectors i, j, and k separately.
 
</p>
 
</p>
<p>
+
<p>
 
For more on custom answer evaluators, see [http://webwork.maa.org/wiki/CustomAnswerCheckers CustomAnswerCheckers] and
 
For more on custom answer evaluators, see [http://webwork.maa.org/wiki/CustomAnswerCheckers CustomAnswerCheckers] and
 
[http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/answerCustom.pl.html answerCustom.pl.html]
 
[http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/answerCustom.pl.html answerCustom.pl.html]
Line 161: Line 428:
   
   
<ul>
 
<li>POD documentation: [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserParametricLine.pl.html parserParametricLine.pl.html]</li>
 
<li>PG macro: [http://cvs.webwork.rochester.edu/viewcvs.cgi/pg/macros/parserParametricLine.pl parserParametricLine.pl]</li>
 
</ul>
 
   
   
  +
<ul>
  +
<li>POD documentation: [http://webwork.maa.org/pod/pg/macros/parserParametricLine.html parserParametricLine.pl]</li>
  +
<li>PG macro: [http://webwork.maa.org/viewvc/system/trunk/pg/macros/parserParametricLine.pl?view=log parserParametricLine.pl]</li>
  +
</ul>
   
 
<ul>
 
<ul>
<li>POD documentation: [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/answerCustom.pl.html answerCustom.pl.html]</li>
+
<li>POD documentation: [http://webwork.maa.org/viewvc/system/trunk/pg/macros/answerCustom.pl?view=log answerCustom.pl.html]</li>
<li>PG macro: [http://cvs.webwork.rochester.edu/viewcvs.cgi/pg/macros/answerCustom.pl answerCustom.pl]</li>
+
<li>PG macro: [http://webwork.maa.org/pod/pg/macros/answerCustom.html answerCustom.pl]</li>
 
</ul>
 
</ul>

Latest revision as of 12:58, 28 June 2023

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 parametric line problem, a vector line segment problem and another vector line segment problem

Vector Valued Functions as Answers


This shows the PG code to check student answers that are vectors whose components are formulas.

  • Example 1: A vector parametric line where the student chooses the parametrization
  • Example 2: A vector parametric line segment where the student chooses the parametrization and the starting and ending times
  • Example 3: A vector parametric line segment where the student must enter a particular parametrization and use particular starting and ending times



Example 1: A vector parametric line where the student chooses the parametrization

Problem Techniques Index

PG problem file Explanation
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserVectorUtils.pl",
"parserParametricLine.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 we need to load parserParametricLine.pl.

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

$P = non_zero_point3D();
$disp = non_zero_vector3D();
$Q = Point($P + $disp);

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
Find a vector parametric equation for the 
line through points \( P = $P \) and \( Q = $Q \).
$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() );

ENDDOCUMENT();

Answer Evaluation: The answer can be any vector parametric line through the points P and Q, so we use ParametricLine("$P + t * $disp") provided by parserParametricLine.pl to allow student answers that use a different parametrization, such as $Q - 2*t * $disp, to be marked correct.

Problem Techniques Index




Example 2: A vector parametric line segment where the student chooses the parametrization and the starting and ending times

Problem Techniques Index

PG problem file Explanation
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserVectorUtils.pl",
"parserParametricLine.pl",
"parserMultiAnswer.pl",
"PGcourse.pl",
);
TEXT(beginproblem());

Initialization: The first three macros should always be loaded for questions whose answers are vector valued functions. We need to load parserParametricLine.pl and parserMultiAnswer.pl since we will want to evaluate the student's answer at the starting and ending times provided by the student.

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

$P = Point(4,0);
$Q = Point(0,2);
$V = Vector(-4,2);

$t = Formula("t");
$line = Vector("$P + $t * $V");

$multians = MultiAnswer( $line, Real("0"), Real("1") )->with(
  singleResult => 0,
  checker => sub {
    my ( $correct, $student, $ansHash ) = @_;
    my ( $linestu, $astu, $bstu ) = @{$student};
    my ( $linecor, $acor, $bcor ) = @{$correct};

    if ( (ParametricLine("$line") == $linestu) &&
         ($linestu->eval(t=>$astu) == $line->eval(t=>"0")) &&
         ($linestu->eval(t=>$bstu) == $line->eval(t=>"1")) ) 
    {  
       return [1,1,1]; 

    } elsif ( (ParametricLine("$line") == $linestu) &&
              ($linestu->eval(t=>$astu) == $line->eval(t=>"0")) )
    {  
       return [1,1,0]; 

    } elsif ( (ParametricLine("$line") == $linestu) &&
              ($linestu->eval(t=>$bstu) == $line->eval(t=>"1")) )
    {  
       return [1,0,1]; 

    } elsif ( (ParametricLine("$line") == $linestu) )
    {
        return [1,0,0];

    } else { 
        return [0,0,0]; 
    }

  }
);

Setup: We create a MutiAnswer answer checker that will evaluate the students vector parametric equation at the starting and ending times provided by the student. For example, both of the student answers (4,0) + t<-4,2> for t between 0 and 1, and (4,0) + t<-2,1> for t between 0 and 2 will be marked correct.

Context()->texStrings;
BEGIN_TEXT
Find a vector parametric equation for the line 
segment from the point \(P = $P\) 
to \(Q = $Q\).  
$BR
\( \vec{r}(t) = \) 
\{ $multians->ans_rule(40 )\}
for 
\{ $multians->ans_rule(5) \}
\( \leq t \leq \)
\{ $multians->ans_rule(5) \}
END_TEXT
Context()->normalStrings;

Main Text: The problem text section of the file is as we'd expect.

$showPartialCorrectAnswers = 1;

ANS( $multians->cmp() );

ENDDOCUMENT(); 

Answer Evaluation: This part is easy since we defined $multians above.

Problem Techniques Index




Example 3: A vector parametric line segment where the student must enter a particular parametrization and use particular starting and ending times

Problem Techniques Index

PG problem file Explanation
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserVectorUtils.pl",
"PGcourse.pl",
);
TEXT(beginproblem());

Initialization: The first three macros should always be loaded for questions whose answers are vector valued functions. For the specific vector parametric line we will use a custom answer checker.

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
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;

#  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( $answer->cmp( checker=>~~&mycheck ) );

ENDDOCUMENT();

Answer Evaluation: There is only one vector parametric equation that describes the position of the object subject to the given conditions, so we want only one answer to be marked correct. We create a custom answer checker mycheck, which is a subroutine that verifies that the student's answer agrees with the correct answer in each component by taking the dot product with the each of the vectors i, j, and k separately.

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

Problem Techniques Index