Hello, I would like to check the answer which is the result of integration.
For example, when integrating "a*exp(a*x)" with respect to x, the correct answer should include exp(a*x), exp(a*x)+5, exp(a*x)+sin(a), exp(a*x)+a^2 etc.
My code is below. It handles answers like exp(a*x)+5, but not exp(a*x)+1/a.
The application includes integrals with parameter, also finding scalar potential to a gradient. My idea is to compare the answers using "upToConstant=>1" for five or ten values of the parameter a. But I do not know how to write such a grader. Also there could be some simpler idea. For example to compare my function and the derivative of the answer from student. But even in this case I do not know how to write this in WeBWorK. Do you have any idea?
Thank you.
-----------------------------------------------
DOCUMENT();
loadMacros(
"PGstandard.pl",
"PGML.pl",
"PGcourse.pl",
);
TEXT(beginproblem());
$showPartialCorrectAnswers = 1;
$b=random(2,10,1);
$c=random(-1,1,2);
Context("Numeric")->variables->add(a=>"Real");
$showPartialCorrectAnswers = 1;
if ($d==0)
{
$funkce=Formula("$b+e^($c*a*x)")->reduce();
$int=Formula("$b*x+e^($c*a*x)/($c*a)");
}
else
{
$funkce=Formula("$b*e^($c*a*x)")->reduce();
$int=Formula("$b*exp($c*a*x)/($c*a)");
}
# $funkce -> reduce();
BEGIN_PGML
Vypočtěte integrál.
>>[``\int [$funkce]\,dx ={}``][_________________________]{$int->cmp(upToConstant=>1,vars=>["x","a"])}[``{}+C``] <<
END_PGML