Difference between revisions of "AnswerUpToMultiplication1"
Jump to navigation
Jump to search
Paultpearson (talk | contribs) |
(add historical tag and give links to newer problems.) |
||
(2 intermediate revisions by 2 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/Algebra/StringOrOtherType.html a newer version of this problem]</p> |
||
+ | |||
+ | |||
<h2>Answer is a Function up to Multiplication by a Nonzero Constant</h2> |
<h2>Answer is a Function up to Multiplication by a Nonzero Constant</h2> |
||
Line 6: | Line 11: | ||
</p> |
</p> |
||
* File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Precalc/AnswerUpToMultiplication1.pg FortLewis/Authoring/Templates/Precalc/AnswerUpToMultiplication1.pg] |
* File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Precalc/AnswerUpToMultiplication1.pg FortLewis/Authoring/Templates/Precalc/AnswerUpToMultiplication1.pg] |
||
+ | * PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Precalc/AnswerUpToMultiplication1_PGML.pg FortLewis/Authoring/Templates/Precalc/AnswerUpToMultiplication1_PGML.pg] |
||
<br clear="all" /> |
<br clear="all" /> |
||
Line 15: | Line 21: | ||
<tr valign="top"> |
<tr valign="top"> |
||
− | <th> PG problem file </th> |
+ | <th style="width: 40%"> PG problem file </th> |
<th> Explanation </th> |
<th> Explanation </th> |
||
</tr> |
</tr> |
||
Line 42: | Line 48: | ||
loadMacros( |
loadMacros( |
||
− | + | 'PGstandard.pl', |
|
− | + | 'MathObjects.pl', |
|
− | + | 'PGML.pl', |
|
+ | 'PGcourse.pl' |
||
); |
); |
||
Line 63: | Line 69: | ||
<td style="background-color:#ffffdd;border:black 1px dashed;"> |
<td style="background-color:#ffffdd;border:black 1px dashed;"> |
||
<pre> |
<pre> |
||
− | Context( |
+ | Context('Numeric'); |
− | $ |
+ | $sol_str = '(x-2)*(x+1)'; |
+ | |||
+ | $ans = Compute($sol_str)->cmp(checker => sub { |
||
+ | my ( $correct, $student, $self ) = @_; |
||
+ | my $context = Context()->copy; |
||
+ | return 0 if $student == 0; |
||
+ | $context->flags->set(no_parameters=>0); |
||
+ | $context->variables->add('C0'=>'Parameter'); |
||
+ | my $c0 = Formula($context,'C0'); |
||
+ | $student = Formula($context,$student); |
||
+ | $correct = Formula($context,"$c0 * $sol_str"); |
||
+ | return $correct == $student; |
||
+ | }); |
||
</pre> |
</pre> |
||
</td> |
</td> |
||
Line 71: | Line 77: | ||
<p> |
<p> |
||
<b>Setup:</b> |
<b>Setup:</b> |
||
+ | </p> |
||
+ | <p> |
||
+ | We use a local context with an adaptive parameter to check the answer. For more on adaptive parameters, see [http://webwork.maa.org/wiki/AdaptiveParameters AdaptiveParameters]. This builds a custom checker that checks if the student answer is a parameter <code>C0</code> multiple of the correct answer in <code>$sol_str</code>. |
||
</p> |
</p> |
||
</td> |
</td> |
||
Line 80: | Line 89: | ||
<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 |
||
+ | Find a quadratic equation in terms of the variable |
||
− | Find a quadratic equation in terms of the variable |
||
+ | [` x `] with roots [` -1 `] and [` 2 `]. |
||
− | \( x \) with roots \( -1 \) and \( 2 \). |
||
+ | |||
− | $BR |
||
+ | [` y = `] [______________]{$ans} |
||
− | $BR |
||
+ | |||
− | \( y = \) \{ ans_rule(20) \} |
||
+ | [@ helpLink('formulas') @]* |
||
− | \{ AnswerFormatHelp("formulas") \} |
||
+ | END_PGML |
||
− | END_TEXT |
||
− | Context()->normalStrings; |
||
</pre> |
</pre> |
||
<td style="background-color:#ffcccc;padding:7px;"> |
<td style="background-color:#ffcccc;padding:7px;"> |
||
<p> |
<p> |
||
<b>Main Text:</b> |
<b>Main Text:</b> |
||
− | </p> |
||
− | </td> |
||
− | </tr> |
||
− | |||
− | <!-- Answer evaluation section --> |
||
− | |||
− | <tr valign="top"> |
||
− | <td style="background-color:#eeddff;border:black 1px dashed;"> |
||
− | <pre> |
||
− | $showPartialCorrectAnswers = 1; |
||
− | |||
− | ANS( $aSolution->cmp(checker => sub { |
||
− | my ( $correct, $student, $self ) = @_; |
||
− | my $context = Context()->copy; |
||
− | return 0 if $student == 0; |
||
− | $context->flags->set(no_parameters=>0); |
||
− | $context->variables->add('C0'=>'Parameter'); |
||
− | my $c0 = Formula($context,'C0'); |
||
− | $student = Formula($context,$student); |
||
− | $correct = Formula($context,"$c0 * $aSolution"); |
||
− | return $correct == $student; |
||
− | } |
||
− | ) ); |
||
− | </pre> |
||
− | <td style="background-color:#eeccff;padding:7px;"> |
||
− | <p> |
||
− | <b>Answer Evaluation:</b> |
||
− | We use a local context with an adaptive parameter to check the answer. For more on adaptive parameters, see [http://webwork.maa.org/wiki/AdaptiveParameters AdaptiveParameters] When <code>$aSolution</code> is "complicated", you may need to replace <code>$c0 * $aSolution</code> in the custom answer checker by its value <code>$c0 * (x-2)(x+1)</code> in order to get things to work correctly. |
||
</p> |
</p> |
||
</td> |
</td> |
||
Line 131: | Line 110: | ||
<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.'); |
||
ENDDOCUMENT(); |
ENDDOCUMENT(); |
Latest revision as of 05:07, 18 July 2023
This problem has been replaced with a newer version of this problem
Answer is a Function up to Multiplication by a Nonzero Constant
This PG code shows how to
- File location in OPL: FortLewis/Authoring/Templates/Precalc/AnswerUpToMultiplication1.pg
- PGML location in OPL: FortLewis/Authoring/Templates/Precalc/AnswerUpToMultiplication1_PGML.pg
PG problem file | Explanation |
---|---|
Problem tagging: |
|
DOCUMENT(); loadMacros( 'PGstandard.pl', 'MathObjects.pl', 'PGML.pl', 'PGcourse.pl' ); TEXT(beginproblem()); |
Initialization: |
Context('Numeric'); $sol_str = '(x-2)*(x+1)'; $ans = Compute($sol_str)->cmp(checker => sub { my ( $correct, $student, $self ) = @_; my $context = Context()->copy; return 0 if $student == 0; $context->flags->set(no_parameters=>0); $context->variables->add('C0'=>'Parameter'); my $c0 = Formula($context,'C0'); $student = Formula($context,$student); $correct = Formula($context,"$c0 * $sol_str"); return $correct == $student; }); |
Setup:
We use a local context with an adaptive parameter to check the answer. For more on adaptive parameters, see AdaptiveParameters. This builds a custom checker that checks if the student answer is a parameter |
BEGIN_PGML Find a quadratic equation in terms of the variable [` x `] with roots [` -1 `] and [` 2 `]. [` y = `] [______________]{$ans} [@ helpLink('formulas') @]* END_PGML |
Main Text: |
BEGIN_PGML_SOLUTION Solution explanation goes here. END_PGML_SOLUTION ENDDOCUMENT(); |
Solution: |