is some more information on these "Gochas". I end with a question for
all the Perl experts out there. Tom has sent off line the code from his
$alpha = random(1,7);
$beta = random(1,7);
$kappa1 = random(1,10);
$kappa2 = random(1,10);
$pi = acos(-1);
$c1 = $kappa1;
$c2 = $kappa2 / exp(($pi * $alpha)/(2 * $beta));
ANS( fun_cmp("($c1) * exp($alpha * t) * cos($beta * t) + ($c2)
* exp($alpha * t) * sin($beta * t)",vars=>['t'] ) );
The seed is 1562.
As an aside he also remarks "BTW the problem has been used by 800 -
1000 students; you would have thought something would have surfaced
before." Some gotchas can be subtle.
Note that above he enclosed $c2 with parentheses which took care of the first gotcha but not the second.
Here is what is happening (I think). My email to Tom:
I added the lines
warn ("c2 is $c2");
which for seed 1562 prints
$d2 = sprintf "%.15G" ,$c2;
warn ("d2 is $d2");
* c2 is 6.71031260969032e-05 at (eval 56) line 32.
* d2 is 6.71031260969032E-05 at (eval 56) line 40.
so I think it's a gotcha. My guess is that for most other seeds it's not of this form. E.g. seed =12 gives
* c2 is 4.59067077420795 at (eval 56) line 38.
Here is a possible solution. Add the line
$c2 = sprintf "%.15G" ,$c2;
Correct answer: (10) * exp(7 * t) * cos(1 * t) + (6.71031260969032E-05) * exp(7 * t) * sin(1 * t)
as the correct answer. This will be handled correctly by WeBWorK.
Adding instead the line
$c2 = sprintf "%.15f" ,$c2; gives
Correct answer: (10) * exp(7 * t) * cos(1 * t) + (0.000067103126097) * exp(7 * t) * sin(1 * t)
Note here you would not have to put parentheses around the $c2 (i.e. it
solves both gotha's) assuming we haven't run into accuracy problems.
Here is a question for Perl experts. It looks like Perl's print command
is equivalent to sprintf "%.15g" .
Could we make it equivalent to sprintf "%.15G " ? This would take care
of the second Gotcha. sprintf "%.15f " or some variant would take care
of both but would most likely lead to other problems.
<| Post or View Comments |>