Difference between revisions of "RestrictedStudentAnswers"
m |
|||
Line 14: | Line 14: | ||
<ul> |
<ul> |
||
<li> [[#Requiring that an answer be simplified to a constant]] </li> |
<li> [[#Requiring that an answer be simplified to a constant]] </li> |
||
+ | <li> [[#Requiring that an answer be a simplified fraction]] </li> |
||
<li> To require that a student answer be simplified to a polynomial, we can use the LimitedPolynomial Context, described on the [[DisableFunctions|Restricting Functions and Operators in Student Answers]] page </li> |
<li> To require that a student answer be simplified to a polynomial, we can use the LimitedPolynomial Context, described on the [[DisableFunctions|Restricting Functions and Operators in Student Answers]] page </li> |
||
<li> <em>...other examples should be added here</em> </li> |
<li> <em>...other examples should be added here</em> </li> |
||
Line 22: | Line 23: | ||
</p> |
</p> |
||
− | <div id="Simplified Answer"></div> |
||
<h3>Requiring that an answer be simplified to a constant</h3> |
<h3>Requiring that an answer be simplified to a constant</h3> |
||
Line 98: | Line 98: | ||
</tr> |
</tr> |
||
</table> |
</table> |
||
+ | |||
+ | <p style="text-align:center;"> |
||
+ | [[#Restricting Allowed Student Answer Formats: PG Code Snippet|top of page]] |
||
+ | </p> |
||
+ | |||
+ | <!-- second section --> |
||
+ | <h3>Requiring that an answer be a simplified fraction</h3> |
||
+ | |||
+ | <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", |
||
+ | "contextFraction.pl", |
||
+ | ); |
||
+ | TEXT(beginproblem()); |
||
+ | </pre> |
||
+ | </td> |
||
+ | <td style="background-color:#ccffcc;padding:7px;"> |
||
+ | <p> |
||
+ | <b>Initialization:</b> We need to include the macro file |
||
+ | <code>contextFraction.pl</code>. |
||
+ | </p> |
||
+ | </td> |
||
+ | </tr> |
||
+ | |||
+ | <!-- Setup section --> |
||
+ | |||
+ | <tr valign="top"> |
||
+ | <td style="background-color:#ffffdd;border:black 1px dashed;"> |
||
+ | <pre> |
||
+ | Context("Fraction-NoDecimals"); |
||
+ | Context()->operators->undefine('+','-','*', |
||
+ | '*','**','^'); |
||
+ | |||
+ | $a = random(2,4,1); |
||
+ | $b = random(1,9,1); |
||
+ | $c = random(1,9,1); |
||
+ | $den = $c + $a*$a; |
||
+ | $frac = Compute("$b/$den"); |
||
+ | </pre> |
||
+ | </td> |
||
+ | <td style="background-color:#ffffcc;padding:7px;"> |
||
+ | <p> |
||
+ | <b>Setup:</b> |
||
+ | Here we specify that we are using the <code>Fractions-NoDecimals</code> |
||
+ | Context, which requires that answers be fractions and not decimals. |
||
+ | To ensure that students do the simplification rather than typing |
||
+ | the answer without expanding it, we undefine operators other than |
||
+ | division (see [[DisableFunctions|Restricting Functions and Operators]]). |
||
+ | </p> |
||
+ | <p> |
||
+ | <strong>Note</strong> that because we've undefined these operators, we |
||
+ | can't define the answer as <code>$frac=Compute("$b/($c + $a^2)");</code>. |
||
+ | The operators <code>+</code> and <code>^</code> are undefined, so we |
||
+ | don't have them available. In this case we do the calculation of the |
||
+ | denominator using Perl first, and then use the MathObject to create the |
||
+ | answer. |
||
+ | </p> |
||
+ | <p> |
||
+ | <strong>Also note</strong> that by default a Fraction will be reduced to |
||
+ | lowest terms. |
||
+ | </td> |
||
+ | </tr> |
||
+ | |||
+ | <!-- Question text section --> |
||
+ | |||
+ | <tr valign="top"> |
||
+ | <td style="background-color:#ffdddd;border:black 1px dashed;"> |
||
+ | <pre> |
||
+ | BEGIN_TEXT |
||
+ | Find and simplify completely the value of |
||
+ | \(f($a)\) if |
||
+ | \[ f(x) = \frac{$b}{$c + x^2}. \] |
||
+ | $BR |
||
+ | \(f($a) = \) |
||
+ | \{ ans_rule(25) \} |
||
+ | $BR |
||
+ | ${BITALIC}(Simplify your answer as much as |
||
+ | possible, and enter a fraction instead of |
||
+ | a decimal.)$EITALIC |
||
+ | END_TEXT |
||
+ | </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( $frac->cmp(studentsMustReduceFractions=>1, |
||
+ | strictFractions=>1,strictMinus=>1, |
||
+ | strictMultiplication=>1) ); |
||
+ | |||
+ | ENDDOCUMENT(); |
||
+ | </pre> |
||
+ | <td style="background-color:#eeccff;padding:7px;"> |
||
+ | <p> |
||
+ | <b>Answer Evaluation:</b> |
||
+ | In the answer evaluation, we require students to reduce fractions, |
||
+ | and by setting the remaining three flags, that the fraction be an |
||
+ | integer over another integer. |
||
+ | </p> |
||
+ | </td> |
||
+ | </tr> |
||
+ | </table> |
||
+ | |||
+ | <ul> |
||
+ | <li> POD documentation: [[http://webwork.maa.org/pod/pg_TRUNK/macros/contextFraction.pl.html contextFraction]] </li> |
||
+ | <li> PG macro: [[http://webwork.maa.org/viewvc/system/trunk/pg/macros/contextFraction.pl?view=log contextFraction.pl]] </li> |
||
+ | </ul> |
||
+ | |||
<p style="text-align:center;"> |
<p style="text-align:center;"> |
||
[[IndexOfProblemTechniques|Problem Techniques Index]] |
[[IndexOfProblemTechniques|Problem Techniques Index]] |
||
</p> |
</p> |
||
+ | |||
+ | |||
[[Category:Problem Techniques]] |
[[Category:Problem Techniques]] |
Revision as of 09:33, 19 October 2011
Restricting Allowed Student Answer Formats: PG Code Snippet
This PG code shows how to check student answers that are equations. Note that this is an insertion, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.
In general, there are a number of different restrictions that one might want to place on a student answer: that it be completely simplified, that it be exact, etc. In the following we consider a number of these. Note that there are often many ways to accomplish the same goals, and the method suggested here may or may not be directly applicable to the case you are considering. Often using a Custom Answer Checker or setting a Custom Error Message will also be desirable.
Examples below:
- #Requiring that an answer be simplified to a constant
- #Requiring that an answer be a simplified fraction
- To require that a student answer be simplified to a polynomial, we can use the LimitedPolynomial Context, described on the Restricting Functions and Operators in Student Answers page
- ...other examples should be added here
Requiring that an answer be simplified to a constant
PG problem file | Explanation |
---|---|
Context("Numeric"); $expr = Formula("sin(x)^2 + cos(x)^2"); $deriv = Compute(0); |
Setup:
The set up section has nothing out of the ordinary. Our variable
|
BEGIN_TEXT Find and simplify completely: $BR \(\frac{d}{dx}\left($expr\right) = \) \{ ans_rule(25) \} END_TEXT |
Main Text: The problem text section of the file is as we'd expect. |
$showPartialCorrectAnswers = 1; ANS( $deriv->cmp(showTypeWarnings=>0) ); ENDDOCUMENT(); |
Answer Evaluation:
Here we've turned off type warnings in the answer checking,
so that a student entering an un-simplified answer (e.g.,
|
Requiring that an answer be a simplified fraction
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "contextFraction.pl", ); TEXT(beginproblem()); |
Initialization: We need to include the macro file
|
Context("Fraction-NoDecimals"); Context()->operators->undefine('+','-','*', '*','**','^'); $a = random(2,4,1); $b = random(1,9,1); $c = random(1,9,1); $den = $c + $a*$a; $frac = Compute("$b/$den"); |
Setup:
Here we specify that we are using the
Note that because we've undefined these operators, we
can't define the answer as Also note that by default a Fraction will be reduced to lowest terms. |
BEGIN_TEXT Find and simplify completely the value of \(f($a)\) if \[ f(x) = \frac{$b}{$c + x^2}. \] $BR \(f($a) = \) \{ ans_rule(25) \} $BR ${BITALIC}(Simplify your answer as much as possible, and enter a fraction instead of a decimal.)$EITALIC END_TEXT |
Main Text: The problem text section of the file is as we'd expect. |
$showPartialCorrectAnswers = 1; ANS( $frac->cmp(studentsMustReduceFractions=>1, strictFractions=>1,strictMinus=>1, strictMultiplication=>1) ); ENDDOCUMENT(); |
Answer Evaluation: In the answer evaluation, we require students to reduce fractions, and by setting the remaining three flags, that the fraction be an integer over another integer. |
- POD documentation: [contextFraction]
- PG macro: [contextFraction.pl]