## WeBWorK Problems by Danny Glin -
Number of replies: 3
I've been working on writing some problems using adaptive parameters by following the wiki entry at http://wwrk.maa.org/wiki/AdaptiveParameters, and I've run into some odd behaviour.

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:
1. (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.
I suspect that the first issue stems from the fact that it uses the custom checker to determine if the current answer and the previous answer are equivalent, which is not really the behaviour that I want students to see. I'm completely stumped on the second one.

Any help would be appreciated.
Thanks,
Danny ### Re: Problems with adaptive parameters

by Davide Cervone -
Both of the problems are related. You are correct that the custom checker is used in the check that determines when the previous answer is the same as the current one, and the same solution will fix both problems.

Here is a modified checker:

    ANS( $aSoln->cmp( checker => sub { my ($correct, $student,$self ) = @_;
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 ($correct)");
}
return $correct ==$student;
}));

This skips the adaptive step if the checker is being called by the "equivalent answer" check, and so it just does a normal equality check.

This fixes both problems. It fixes 1 because the message will only be issued when the two are actually equal as functions, since the adaptive parameter is never involved.

It fixes 2 in the following way: the check for equivalent answers is done by passing the previous answer as the "correct" answer and the new answer as the "student" answer. In the case where the previous answer was 0, you ended up with "C0 (0)" as the formula, and you can't solve for C0 in that case (you effectively get division by zero), so the $correct ==$student check fails to produce an answer (the actual error message has been suppressed, but it is probably "can't solve for adaptive parameter" or some such thing). In any case, avoiding the adaptive parameter during the equivalence check should take care of it for you.

It is probably worth updating the Wiki example to reflect this. (Note that you don't really need the \$c0 variable, as you can just use C0 directly in the new formula for the correct answer).

Hope that helps.

Davide ### Re: Problems with adaptive parameters

by Danny Glin -
Yup, that did it.
Thanks.
Danny 