Forum archive 2000-2006

Lars Jensen - exact numerical answer?

Lars Jensen - exact numerical answer?

by Arnold Pizer -
Number of replies: 0
inactiveTopicexact numerical answer? topic started 8/1/2004; 5:19:05 PM
last post 8/6/2004; 5:37:58 PM
userLars Jensen - exact numerical answer?  blueArrow
8/1/2004; 5:19:05 PM (reads: 1211, responses: 6)
How do I get webwork2 to require a student put in the exact answer for a problem with an answer like sqrt(3)/2 ? I tried this:

&ANS(num_cmp(sqrt(3)/2,mode => 'std',tol => 0));

but when the answer sqrt(3)/2 is entered, webwork2 marks it wrong:

Entered, Answer Preview, Correct, Result

0.866025403784439, sqrt(3)/2, 0.866025403784439, incorrect

Even though the "Entered" and "Correct" results are identical, webwork marks the answer incorrect. (Note again, the answer was entered in the answer box by the student in the form sqrt(3)/2, not as 0.866025403784439)

Thanks, Lars.

<| Post or View Comments |>


userJohn Jones - Re: exact numerical answer?  blueArrow
8/1/2004; 7:48:50 PM (reads: 1355, responses: 0)
Hi Lars,

Setting the tolerance to zero is not a very good solution. In this case, you could load PGasu.pl and use

ANS( no_decimals("sqrt(3)/2") );

It does a normal num_cmp, but the student answer is not allowed to include a decimal point. Any optional arguments should be passed to num_cmp.

Depending on the question, you may want to disallow trig functions from the student's answer as well (e.g., if this question is "What is sin(pi/3)?", you probably don't want "sin(pi/3)" as an answer). There are functions for that kind of thing in PGasu also, I think it is called exact_no_trig.

John

<| Post or View Comments |>


userLars Jensen - Re: exact numerical answer?  blueArrow
8/3/2004; 6:31:26 PM (reads: 1339, responses: 0)
Hi John,

Thanks for the response. This does work. When webwork2 shows the correct answer to the student, will it show it as sqrt(3)/2 or 0.866025403784439 ?

Lars.

<| Post or View Comments |>


userJohn Jones - Re: exact numerical answer?  blueArrow
8/3/2004; 8:23:31 PM (reads: 1354, responses: 0)
Hi Lars,

I haven't tried it in a long time. I am pretty sure that if shown as above with the quotes, it should show sqrt(3)/2 (except for a known the webwork bug).

John

PS. The bug applies to any time num_cmp is used: if the student answer is blank and the correct answer is requested, a floating point version is always shown.

<| Post or View Comments |>


userLars Jensen - Re: exact numerical answer?  blueArrow
8/4/2004; 5:30:58 AM (reads: 1390, responses: 0)
Hi John,

Thanks again. Using

ANS( no_decimals("sqrt(3)/2") );

works as expected. But if the answer depends on a variable, or is specified in the form:

$ans = sqrt(3)/2;

ANS( no_decimals("$ans") );

then the correct answer is returned to the student in the form 0.866025403784439

Lars.

<| Post or View Comments |>


userJohn Jones - Re: exact numerical answer?  blueArrow
8/4/2004; 10:33:41 AM (reads: 1350, responses: 0)
Hi Lars,

The line

$ans = sqrt(3)/2;

is where the answer is computed as a floating point number. You want

$ans = "sqrt(3)/2";

In that spot instead.

John

<| Post or View Comments |>


userLars Jensen - Re: exact numerical answer?  blueArrow
8/6/2004; 5:37:58 PM (reads: 1323, responses: 0)
Got it! Thanks, John.

<| Post or View Comments |>