Difference between revisions of "AnswerWithUnits1"
Jump to navigation
Jump to search
Paultpearson (talk | contribs) (Add link to PGML version in OPL) |
(Switch to PGML.) |
||
Line 5: | Line 5: | ||
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> |
||
− | * File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/DiffCalc/AnswerWithUnits1.pg FortLewis/Authoring/Templates/DiffCalc/AnswerWithUnits.pg] |
||
+ | |||
* 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] |
* 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] |
||
Line 16: | Line 16: | ||
<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 43: | ||
loadMacros( |
loadMacros( |
||
− | + | 'PGstandard.pl', |
|
− | + | 'MathObjects.pl', |
|
− | + | 'parserNumberWithUnits.pl', |
|
− | + | 'parserFormulaWithUnits.pl', |
|
+ | 'PGML.pl', |
||
+ | 'PGcourse.pl' |
||
); |
); |
||
Line 66: | Line 66: | ||
<td style="background-color:#ffffdd;border:black 1px dashed;"> |
<td style="background-color:#ffffdd;border:black 1px dashed;"> |
||
<pre> |
<pre> |
||
− | Context( |
+ | Context('Numeric')->variables->are(t=>'Real'); |
− | $h = Formula( |
+ | $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'); |
||
− | $ |
+ | $answer1 = FormulaWithUnits("$v",'ft/s'); |
− | $ |
+ | $answer2 = NumberWithUnits("$v1",'ft/s'); |
− | $ |
+ | $answer3 = FormulaWithUnits("$a",'ft/s^2'); |
</pre> |
</pre> |
||
</td> |
</td> |
||
Line 91: | Line 91: | ||
<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 |
||
+ | a. What is the velocity of the object? [______________]{$answer1} |
||
− | seconds. |
||
+ | |||
− | $BR |
||
+ | b. What is the velocity of the object when it hits the ground? [______________]{$answer2} |
||
− | $BR |
||
+ | |||
− | + | c. What is the acceleration of the object? Include units in your answer. [______________]{$answer3} |
|
− | + | ||
− | + | Note: use units in all answers. [@ helpLink('units') @]* |
|
− | + | END_PGML |
|
− | \{ 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> |
</pre> |
||
<td style="background-color:#ffcccc;padding:7px;"> |
<td style="background-color:#ffcccc;padding:7px;"> |
||
Line 108: | Line 108: | ||
<b>Main Text:</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. |
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> |
||
− | </td> |
||
− | </tr> |
||
− | |||
− | <!-- Answer evaluation section --> |
||
− | |||
− | <tr valign="top"> |
||
− | <td style="background-color:#eeddff;border:black 1px dashed;"> |
||
− | <pre> |
||
− | $showPartialCorrectAnswers = 1; |
||
− | |||
− | foreach my $i (0..2) { |
||
− | ANS( $answer[$i]->cmp() ); |
||
− | } |
||
− | </pre> |
||
− | <td style="background-color:#eeccff;padding:7px;"> |
||
− | <p> |
||
− | <b>Answer Evaluation:</b> |
||
</p> |
</p> |
||
</td> |
</td> |
||
Line 135: | Line 117: | ||
<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 |
||
Solution explanation goes here. |
Solution explanation goes here. |
||
− | END_SOLUTION |
||
+ | END_PGML_SOLUTION |
||
− | Context()->normalStrings; |
||
− | COMMENT(' |
+ | COMMENT('Uses PGML.'); |
ENDDOCUMENT(); |
ENDDOCUMENT(); |
Revision as of 07:36, 11 March 2023
Answer is a Number or Formula with Units
This PG code shows how to require students to enter units with their answers.
- PGML location in OPL: FortLewis/Authoring/Templates/DiffCalc/AnswerWithUnits1_PGML.pg
PG problem file | Explanation |
---|---|
Problem tagging: |
|
DOCUMENT(); loadMacros( 'PGstandard.pl', 'MathObjects.pl', 'parserNumberWithUnits.pl', 'parserFormulaWithUnits.pl', 'PGML.pl', 'PGcourse.pl' ); TEXT(beginproblem()); |
Initialization:
We load |
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 |
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 |
BEGIN_PGML_SOLUTION Solution explanation goes here. END_PGML_SOLUTION COMMENT('Uses PGML.'); ENDDOCUMENT(); |
Solution: |