Creates an answer evaluator which checks numerical answers.
num_cmp([num1, num2], options)
The first argument is the correct numerical answer, or one or more correct answers placed in square brackets. The options are specified in
key => value(see Options)
Option key Option value Default mode 'std' -- (default) - allows any expression evaluating to a number
'frac' -- fractions are allowed
'arith' -- arithmetic expressions allowed
'strict' -- only numbers are allowed
'std' tol an absolute tolerance for checking answers -- the default is to use relative tolerance reltol -- a relative tolerance given in percent. The submitted answer is judged correct if
|submit_ans-corr_ans| < .01 * reltol *corr_ans.
.01 per cent format defines formatting for printing the correct answer using the perl and C conventions.
units specifies that the answer must include units and specifies the units used for the correct answer. strings specifies a list of words which are also allowed. (e.g. -- ['infinity','minus_infinity','undefined'] ). Note the required square brackets.
One (or more) answer evaluators
num_cmp( 5, mode => 'strict' )allows only 5 as an answer. No calculations are done.
num_cmp( 5, mode => 'arith' )allows (3+7)/2 as an answer but not (2 +6)/2 + cos(0)
num_cmp( 5, mode => 'frac' )allows 10/2 as an answer but not 3+5. This option is intended to allow numbers containing fractions, but it general will not do arithmetic operations.
num_cmp( 5 ) or num_cmp(5, mode =>'std')allow cos(0) + e^0 +6/2 as an answer
num_cmp(10, tol => 1)requires an answer between 9 and 11.(There is ambiguity at the endpoints.)
num_cmp(10, reltol=>1)requires an answer between 9.9 and 10.1 -- i.e. within 1% of the correct answer. (reltol is defined in percent!)
num_cmp( 3.1415926, format =>'%0.3f' )prints as 3.141
num_cmp( 3.14159, format => '%0.4e' )prints as 3.1415
num_cmp( 3.14159, format =>'%0.3g' )gives 4 figures in either fixed point or exponential notation depending on the size. In this case 3.14. For very small or large numbers the answer would be printed using exponential notation.
num_cmp(5, units => 'cm')requires '5 cm' or '50 mm' or '.05 m' as an answer. The submitted answer must have a space before the unit and no spaces within the units.
num_cmp(5, strings =>['undefined'])requires either a 5 or 'undefined' as an answer.
The options can be used in any combination that makes sense, and probably some that don't. One exception:
tolcannot be used together.