For example, I'd like to ask my students to take the nth derivative of cos(2x) or sin(2x), where 50 < n < 100.
I'm running into an issue: if I ask for the derivative itself, the correct answer may be marked incorrect because of floating point issues. As an example, entering -(2^82)*cos(2x) for the 82nd derivative of cos(2x) is marked incorrect, but -(4.8357*e+24)*cos(2x) is marked correct. (I'm using MathObjects, so the function is defined as a Formula object).
One way to get a sense of what is happening is to add diagnostics=>1
to the answer checker, as in
ANS($f->cmp(diagnostics=>1));This will cause the problem to generate a diagnostic table showing the values used within the comparison for both the student and correct answers and whether they were within the tolerances or not. Often this can help determine what is going wrong.
Formulas involving very large and very small values tend to be problematic, and setting the tolerances and limits properly can be very important. In my experience, one of the most important caveats is to try to avoid the zeros of the function, as relative tolerances work poorly near values of zero.
Note that in your case, the default limits of -2 to 2 in the x value will include several zeros of the function, and depending on the problem seed, that course lead to incorrect results like what you have seen. You may find that restricting the limits to a range where the function is non-zero will help, say -pi/6 to pi/6 in your case.
Alternatively, you may need to use a custom answer checker for this. For example, it could evaluate the student function at x=0 (to determine the constant used by the student) and if it is not correct, mark the answer as false, while if it is correct, it could divide the student answer by that constant and compare it to cos(2x), which will no longer be enormously large values. I haven't tried that, but I think it would work. Anyway, it is worth a try.
Davide