Adaptive Parameters

Utilizing adaptive parameters in checkers.

Complete Code

Download file: AdaptiveParameters.pg

PG problem file

Explanation

DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'PGcourse.pl');

Preamble

These standard macros need to be loaded.
$aSoln = Compute('e^x - 1')->cmp(
    checker => sub {
        my ($correct, $student, $ans) = @_;
        # return 0 if $student == Formula(0); # See comments.
        if ($self->{_filter_name} ne 'produce_equivalence_message') {
            my $context = Context()->copy;
            $context->flags->set(no_parameters => 0);
            $context->variables->add(C0 => 'Parameter');
            $student = Formula($context, $student);
            $correct = Formula($context, 'C0 * e^x - 1');
        }
        return $correct == $student;
    }
);

Setup

This problem will utilize with adaptive parameters in the custom answer checker. Define $aSoln to be the result of calling cmp on a MathObject function with the checker option set.

The general solution to the differential equation in this problem is y = cex − 1. The student will be asked to enter a specific solution like y = e2ex − 1. Adaptive parameters will be used to check that the student’s answer has the correct form.

The custom answer checker creates a copy of the Context in which an adaptive parameter is allowed. It then re-computes the student and correct answers in that context. Then it checks that the answers match with the adaptive parameter.

If it is desired to allow a solution to differ by an additive constant from the answer in the problem, this can be accomplished using existing MathObjects methods, as discussed on the formulas up to constants page.

If the answers may be a pure multiple of the correct answer without an additive constant, then 0 should not be considered correct. For example, if the general solution were ce^x. So the commented out line return 0 if $student == Formula(0); would needed in that case.

Observe that this checker bypasses the adaptive parameter code for the ‘produce_equivalence_message’ filter. This filter compares the current student answer to the previous student answer and gives the message “This answer is equivalent to the one you just submitted.” in the case that the two are deemed to be equal. That message could be confusing to students for two answers with different constants in this type of problem.

BEGIN_PGML
Find one solution to the differential equation.

    [`\frac{dy}{dx} = y + 1`]

[`y =`] [_]{$aSoln}
END_PGML

Statement

This is the problem statement in PGML.
BEGIN_PGML_SOLUTION

END_PGML_SOLUTION

ENDDOCUMENT();

Solution

A solution should be provided here.