WeBWorK Problems

Constants and General Solutions to ODEs

Re: Constants and General Solutions to ODEs

by Alex Jordan -
Number of replies: 0
Hi Lynda,

I know you posted this question a long time ago, but I just wrestled with this problem, and the "solution" I came works like this:

Students will be required to use C for the arbitrary constant, and C should be added as a variable to the context.

Next suppose "the" answer is:
$answer = Formula("1/(x+C)");

which is the solution to
y' = -y^2

Make a custom answer checker that checks for two things:
1. the student's answer solves the differential equation
2. whatever the student has entered in place of C is a linear (and nonconstant) function of C

I probably do not have the most efficient way to do this, but my custom checker works like this:

ANS( $answer->cmp( checker=>sub {
my ( $correct, $student, $ansHash ) = @_;

my $dstudent = $student->D('x');
my $lhs = Formula("$dstudent");
my $rhs = Formula("-($student)^2");

my $studentC = Formula("1/$student - x");
my $dstudentC = $studentC->D('C');
my $ddstudentC = $dstudentC->D('C');

if (($lhs == $rhs) && ($ddstudentC == Formula("0")))
{ if ($dstudentC != Formula("0"))
{return 1}
else {Value->Error("Your answer is not the most general solution.")}
else {return 0};
} ) );

This lets students enter things like 1/(x+2C-5), if that happens to be where they ended up after solving process. There is a check in there that prevents things like 1/(x+5) from being counted as correct too. Ideally, the checker would allow 1/(x+f(C)) for any one-to-one function f that covers R, but I don't know how to check that. Looking at first and second derivatives lets us check linearity though.

Take care if you use this in problems where the answer has domain issues.