Difference between revisions of "AnswerWithUnits1"

From WeBWorK_wiki
Jump to navigation Jump to search
(Created page with '<h2>Answer is a Number or Formula with Units</h2> 300px|thumb|right|Click to enlarge <p style="background-color:#f9f9f9;border:black solid 1px;padd…')
 
(add historical tag and give links to newer problems.)
 
(5 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/DiffCalc/AnswerWithUnits.html a newer version of this problem]</p>
  +
  +
 
<h2>Answer is a Number or Formula with Units</h2>
 
<h2>Answer is a Number or Formula with Units</h2>
   
Line 5: Line 10:
 
This PG code shows how to require students to enter units with their answers.
 
This PG code shows how to require students to enter units with their answers.
 
</p>
 
</p>
* Download file: [[File:AnswerWithUnits1.txt]] (change the file extension from txt to pg when you save it)
 
  +
* File location in NPL: <code>FortLewis/Authoring/Templates/DiffCalc/AnswerWithUnits.pg</code>
 
  +
* PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/DiffCalc/AnswerWithUnits1_PGML.pg FortLewis/Authoring/Templates/DiffCalc/AnswerWithUnits1_PGML.pg]
   
 
<br clear="all" />
 
<br clear="all" />
Line 16: Line 21:
   
 
<tr valign="top">
 
<tr valign="top">
<th> PG problem file </th>
+
<th style="width: 50%"> PG problem file </th>
 
<th> Explanation </th>
 
<th> Explanation </th>
 
</tr>
 
</tr>
Line 43: Line 48:
   
 
loadMacros(
 
loadMacros(
"PGstandard.pl",
+
'PGstandard.pl',
"MathObjects.pl",
+
'MathObjects.pl',
"parserNumberWithUnits.pl",
+
'parserNumberWithUnits.pl',
"parserFormulaWithUnits.pl",
+
'parserFormulaWithUnits.pl',
  +
'PGML.pl',
  +
'PGcourse.pl'
 
);
 
);
   
Line 55: Line 60:
 
<p>
 
<p>
 
<b>Initialization:</b>
 
<b>Initialization:</b>
  +
We load <code>parserNumberWithUnits.pl</code> and <code>parserFormulaWithUnits.pl</code>.
 
</p>
 
</p>
 
</td>
 
</td>
Line 65: Line 71:
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context("Numeric")->variables->are(t=>"Real");
+
Context('Numeric')->variables->are(t=>'Real');
   
$h = Formula("-16 t^2 + 16");
+
$h = Formula('-16 t^2 + 16');
 
$v = $h->D('t');
 
$v = $h->D('t');
 
$v1 = $v->eval(t=>1);
 
$v1 = $v->eval(t=>1);
 
$a = $v->D('t');
 
$a = $v->D('t');
   
$answer[0] = FormulaWithUnits("$v","ft/s");
+
$answer1 = FormulaWithUnits("$v",'ft/s');
$answer[1] = NumberWithUnits("$v1","ft/s");
+
$answer2 = NumberWithUnits("$v1",'ft/s');
$answer[2] = FormulaWithUnits("$a","ft/s^2");
+
$answer3 = FormulaWithUnits("$a",'ft/s^2');
 
</pre>
 
</pre>
 
</td>
 
</td>
Line 80: Line 86:
 
<p>
 
<p>
 
<b>Setup:</b>
 
<b>Setup:</b>
  +
We use the differentiation operator <code>-&gt;D('t')</code> and the evaluation method <code>-&gt;eval()</code> to construct the derivative and evaluate it as a function. If we were writing several questions like this with different height functions, using the differentiation and evaluation methods would really speed up the writing.
 
</p>
 
</p>
 
</td>
 
</td>
Line 89: Line 96:
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context()->texStrings;
 
  +
BEGIN_PGML
BEGIN_TEXT
 
  +
Suppose the height of a falling object, in feet above the ground, is given by
Suppose the height of a falling object, in feet
 
  +
[` h(t) = [$h] `] for [` t \geq 0 `], where time is measured in seconds.
above the ground, is given by \( h(t) = $h \)
 
for \( t \geq 0 \), where time is measured in
 
seconds.
 
$BR
 
$BR
 
(a) What is the velocity of the object? Include
 
units in your answer.
 
$BR
 
\{ ans_rule(20) \}
 
\{ helpLink("units") \}
 
$BR
 
$BR
 
(b) What is the velocity of the object when it
 
hits the ground? Include units in your answer.
 
$BR
 
\{ ans_rule(20) \}
 
\{ helpLink("units") \}
 
$BR
 
$BR
 
(c) What is the acceleration of the object?
 
Include units in your answer.
 
$BR
 
\{ ans_rule(20) \}
 
\{ helpLink("units") \}
 
END_TEXT
 
Context()->normalStrings;
 
</pre>
 
<td style="background-color:#ffcccc;padding:7px;">
 
<p>
 
<b>Main Text:</b>
 
</p>
 
</td>
 
</tr>
 
   
<!-- Answer evaluation section -->
 
  +
a. What is the velocity of the object? [______________]{$answer1}
   
<tr valign="top">
 
  +
b. What is the velocity of the object when it hits the ground? [______________]{$answer2}
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<pre>
 
$showPartialCorrectAnswers = 1;
 
   
foreach my $i (0..2) {
 
  +
c. What is the acceleration of the object? Include units in your answer. [______________]{$answer3}
ANS( $answer[$i]->cmp() );
 
  +
}
 
  +
Note: use units in all answers. [@ helpLink('units') @]*
  +
END_PGML
 
</pre>
 
</pre>
<td style="background-color:#eeccff;padding:7px;">
+
<td style="background-color:#ffcccc;padding:7px;">
 
<p>
 
<p>
<b>Answer Evaluation:</b>
+
<b>Main Text:</b>
  +
Don't forget to use <code>helpLink("units")</code> so your students will have access to the complete list of units that WeBWorK understands.
 
</p>
 
</p>
 
</td>
 
</td>
Line 149: Line 121:
 
<td style="background-color:#ddddff;border:black 1px dashed;">
 
<td style="background-color:#ddddff;border:black 1px dashed;">
 
<pre>
 
<pre>
Context()->texStrings;
 
  +
BEGIN_PGML_SOLUTION
BEGIN_SOLUTION
 
${PAR}SOLUTION:${PAR}
 
 
Solution explanation goes here.
 
Solution explanation goes here.
END_SOLUTION
 
  +
END_PGML_SOLUTION
Context()->normalStrings;
 
   
COMMENT('MathObject version.');
+
COMMENT('Uses PGML.');
   
 
ENDDOCUMENT();
 
ENDDOCUMENT();
Line 174: Line 143:
   
 
[[Category:Top]]
 
[[Category:Top]]
[[Category:Authors]]
+
[[Category:Sample Problems]]
  +
[[Category:Subject Area Templates]]

Latest revision as of 05:10, 18 July 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 newer version of this problem


Answer is a Number or Formula with Units

Click to enlarge

This PG code shows how to require students to enter units with their answers.


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT(); 

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

TEXT(beginproblem());

Initialization: We load parserNumberWithUnits.pl and parserFormulaWithUnits.pl.

Context('Numeric')->variables->are(t=>'Real');

$h = Formula('-16 t^2 + 16');
$v = $h->D('t');
$v1 = $v->eval(t=>1);
$a = $v->D('t');

$answer1 = FormulaWithUnits("$v",'ft/s');
$answer2 = NumberWithUnits("$v1",'ft/s');
$answer3 = FormulaWithUnits("$a",'ft/s^2');

Setup: We use the differentiation operator ->D('t') and the evaluation method ->eval() to construct the derivative and evaluate it as a function. If we were writing several questions like this with different height functions, using the differentiation and evaluation methods would really speed up the writing.

BEGIN_PGML
Suppose the height of a falling object, in feet above the ground, is given by
[` h(t) = [$h] `] for [` t \geq 0 `], where time is measured in seconds.

a. What is the velocity of the object?  [______________]{$answer1}

b. What is the velocity of the object when it hits the ground? [______________]{$answer2}

c. What is the acceleration of the object?  Include units in your answer. [______________]{$answer3}

Note: use units in all answers. [@ helpLink('units') @]*
END_PGML

Main Text: Don't forget to use helpLink("units") so your students will have access to the complete list of units that WeBWorK understands.

BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

COMMENT('Uses PGML.');

ENDDOCUMENT();

Solution:

Templates by Subject Area