AnswerUpToMultiplication1: Difference between revisions
		
		
		
		Jump to navigation
		Jump to search
		
| Paultpearson (talk | contribs)  (PGML example link) |  (Switch to PGML and remove AnswerFormatHelp) | ||
| Line 16: | Line 16: | ||
| <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 43: | Line 43: | ||
| loadMacros( | loadMacros( | ||
|   'PGstandard.pl', | |||
|   'MathObjects.pl', | |||
|   'PGML.pl', | |||
|   'PGcourse.pl' | |||
| ); | ); | ||
| Line 64: | Line 65: | ||
| <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 72: | Line 85: | ||
| <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 81: | Line 97: | ||
| <td style="background-color:#ffdddd;border:black 1px dashed;"> | <td style="background-color:#ffdddd;border:black 1px dashed;"> | ||
| <pre> | <pre> | ||
| BEGIN_PGML | |||
| Find a quadratic equation in terms of the variable | |||
| Find a quadratic equation in terms of the variable   | [` x `] with roots [` -1 `] and [` 2 `]. | ||
| [` y = `] [______________]{$ans} | |||
| [@ helpLink('formulas') @]* | |||
| END_PGML | |||
| </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> | </p> | ||
| </td> | </td> | ||
| Line 132: | Line 118: | ||
| <td style="background-color:#ddddff;border:black 1px dashed;"> | <td style="background-color:#ddddff;border:black 1px dashed;"> | ||
| <pre> | <pre> | ||
| BEGIN_PGML_SOLUTION | |||
| Solution explanation goes here. | Solution explanation goes here. | ||
| END_PGML_SOLUTION | |||
| ENDDOCUMENT(); | ENDDOCUMENT(); | ||
Revision as of 11:25, 11 March 2023
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: |