## WeBWorK Problems

### Problem with Fractions in Answer ### Problem with Fractions in Answer

by Daniele Arcara -
Number of replies: 2
I assigned a trigonometric integral with a random variable, and I was having problems when the answer involved a fraction with infinite digits (in the particular case, 1/6). The integral was the integral of sin^a(x)*cos(x), with an answer of 1/(a+1)*(sin(x))^(a+1). When a is 5, the system seems to round the 1/6 in my answer, and then not recognize a student answer as correct when they put the 1/6 in it. I wonder if the 'upToConstant' has something to do with it...

Here is my code:

DOCUMENT();

"PGstandard.pl",
"PGML.pl",
"PGcourse.pl"
);

TEXT(beginproblem());

$a = random(3,7,2);$f = Formula("(sin x)**($a)*(cos x)");$F = Formula("1/($a+1)*(sin x)**($a+1)");

$ans =$F;

BEGIN_PGML

[ \int (\sin x)^[$a] \cos x \, dx = ] [_______________________]{$ans->cmp(upToConstant=>1)} [ +C ]

END_PGML

ENDDOCUMENT;

To temporarily fix the issue, I added the following lines of code after my definition of $a: if ($a == 5)
{ $a = 7; } if ($a == 6)
{ $a = 7; } Thank you for the help. In reply to Daniele Arcara ### Re: Problem with Fractions in Answer by Danny Glin - This works for me on WeBWorK 2.11. See the attached screenshot. Does this happen every time, or just sometimes? My one guess is that for a particular seed the x values chosen lead to very small values of sin^6x, which makes the rounded version fall outside the tolerance for the question. Danny  In reply to Daniele Arcara ### Re: Problem with Fractions in Answer by Alex Jordan - This is not about your answer checking issue, but if you would like the correct answer to *display* with things like 1/6 instead of 0.1666... then one option is you can replace:$F = Formula("1/($a+1)*(sin x)**($a+1)");

with

Context()->flags->set(reduceConstants=>0);
$a1 =$a + 1;
$F = Formula("1/$a1*(sin x)**($a1)"); or just replace that one line with:$F = Formula("(sin x)**($a+1)/($a+1)");

if you are OK with putting the denominator there.