## WeBWorK Problems

### Integral with parameter - grader ### Integral with parameter - grader

by Robert Mařík -
Number of replies: 1

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_PGMLVypočtěte integrál.>>[\int [$funkce]\,dx ={}][_________________________]{$int->cmp(upToConstant=>1,vars=>["x","a"])}[{}+C] <<END_PGML ### Re: Integral with parameter - grader

by Robert Mařík -
I found the solution: differentiate the student's answer and check the derivatives. It may help someone else. R.

DOCUMENT();
loadMacros(    "PGstandard.pl",    "PGML.pl",    "PGcourse.pl",);
TEXT(beginproblem());
$showPartialCorrectAnswers = 1; $showHint = 1;
$b=random(2,10,1); $c=random(-1,1,2);
$d=non_zero_random(-10,18,2); $f=random(-10,10,1);
$n=random(3,6,1); $n1=$n+1; 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)")->reduce();
}
else
{
    $funkce=Formula("$b*e^($c*a*x)")->reduce();  $int=Formula("$b*e^($c*a*x)/($c*a)")->reduce(); } $funkce2=Formula("$d*x+a*x^($n)")->reduce();
$int2=Formula("1/2*($d)*x^2+a/$n1*x^($n1)")->reduce();
sub mycheck {
  my ($correct,$student, $ansHash) = @_;  return$correct->D(x) == $student->D(x); } BEGIN_PGML ## Integrál s parametrem Integrály s parametrem nejsou nic jiného než klasické integrály s drobnou modifikací: namísto hodnot koeficientů vyjádřených numerickou hodnotou obsahují parametr. Z hlediska výpočtu se nic nemění. Proto například můžeme psát [ \int 7x^3+a x^8\,\mathrm dx=\frac 74 x^4+\frac a9 x^9+C.] -------------------------- Vypočtěte integrál funkce proměnné [x] s parametrem [a]. >>[\int [$funkce2]\,\mathrm dx ={}][_________________________]{$int2->cmp(vars=>["x","a"] , checker=>~~&mycheck )}[{}+C] << >>[\int [$funkce]\,\mathrm dx ={}][_________________________]{$int->cmp(vars=>["x","a"] , checker=>~~&mycheck )}[{}+C] << END_PGML BEGIN_PGML_HINT Úloha je podobná jako předchozí, jenom je místo čísla parametr [a]. Představte si místo parametru číslo,  END_PGML_HINT BEGIN_PGML_SOLUTION Úloha je podobná jako předchozí, jenom je místo čísla parametr [a].  [\int [$funkce2]\,\mathrm dx =[$int2]+C] [\int [$funkce]\,\mathrm dx =[\$int]+C]
END_PGML_SOLUTION
ENDDOCUMENT();