AnswerUpToMultiplication1

From WeBWorK_wiki
Jump to navigation Jump to search
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 Function up to Multiplication by a Nonzero Constant

Click to enlarge

This PG code shows how to


Templates by Subject Area

PG problem file Explanation

Problem tagging data

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 C0 multiple of the correct answer in $sol_str.

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:

Templates by Subject Area