Here is my code:
$aSoln = Compute("e^x");
BEGIN_TEXT
Find one solution to the differential equation
\[ \frac{dy}{dx} = y. \]
\( y = \) \{ ans_rule(35) \}
END_TEXT
ANS( $aSoln->cmp( checker => sub {
my ( $correct, $student, $self ) = @_;
my $context = Context()->copy;
$context->flags->set(no_parameters=>0);
$context->variables->add('C0'=>'Parameter');
my $c0 = Formula($context,'C0');
$student = Formula($context,$student);
$correct = Formula($context,"$c0 ($correct)");
return $correct == $student;
}));
The only change I've made in the checker compared to the code in the wiki is to repace
$correct = Formula($context,"$c0 e^x - 1");
with
$correct = Formula($context,"$c0 ($correct)");
so that I don't have to hard code the correct function into the checker (since all I am looking for is any scalar multiple of the correct function).
Two problems I've run into:
- (which also occurs with the original code from the wiki) I get the message "This answer is equivalent to the one you just submitted" any time I submit an answer which is a scalar multiple of my previous answer. This also means that for my code it considers any answer equivalent to 0.
- When I submit an answer of 0 followed by any other answer, I get a pink screen with the warning message "Please inform your instructor that an error occurred while checking your answer at [PG]/lib/Value/AnswerChecker.pm line 247".
Any help would be appreciated.
Thanks,
Danny