## WeBWorK Problems

### Can't take acos of 1 or -1?

by Chrissy Safranski -
Number of replies: 5
I wrote a linear algebra inner product problem, similar to the ones in the library, and it worked perfectly, except with seeds where it was trying to take the inverse cosine of 1 or -1, and then the problem wouldn't render at all and gave the error in my subject line. Any ideas why that would be the case? Both those values are in the domain of arccos, obviously.

The relevant part of my code had looked like this:
$norm_u = sqrt($norm_u);
$norm_v = sqrt($norm_v);
$angle = arccos($prod/$norm_u /$norm_v );

Once the problem was brought to my attention, I was able to fix it, by doing this:

if ($prod>0 and$prod*$prod ==$norm_u *$norm_v ) {$angle=0;}
elsif ($prod<0 and$prod*$prod ==$norm_u * $norm_v ){$angle=pi;}
else {$angle = arccos($prod/sqrt($norm_u) /sqrt($norm_v) ); }

$norm_u = sqrt($norm_u);
$norm_v = sqrt($norm_v);

But my first attempts at a fix also failed to work, like putting the if-clause after I had taken the square roots (the if-clause wouldn't trigger and the same error would occur).

I am running an older version of WebWork (2.10), but this still seems like a weird problem to have.