"Number" (Comparison Method)

Compare two numeric quantities based on a tolerance.

Details

  • The number comparison method considers two numeric quantities to be equivalent if they do not differ numerically beyond a given tolerance.
  • The numeric tolerance should usually be set using the Tolerance option in AssessmentFunction. The default value of 0 allows only machine precision differences.
  • By default, the tolerance is compared to the absolute difference between the answer key value and the answer. The DistanceFunction option can be used to specify a different distance metric.
  • When multiple values in the answer key are within the tolerance range of an answer, the closest value is selected.

Examples

open allclose all

Basic Examples  (3)

Create an AssessmentFunction for a number comparison question:

Use it to assess an answer:

Numerically, approximation is always performed and equivalence is tested by default at machine precision level:

Create a check for an approximate number:

Answers within the tolerance range are correct:

Any other value is marked incorrect:

"Number" is chosen automatically when all values in the answer key are numeric. Define assessment for a problem with multiple correct answers:

Use it to assess answers:

With no Tolerance specified, values not in the key are incorrect:

Scope  (5)

Create an assessment for a list of answers, with each element assessed individually:

Assess a list of answers:

Each answer is assessed and scored separately. By default, any incorrect answer gives an overall incorrect result:

Use "ListAssessment""AllElementsOrdered" to create an assessment function for an ordered list of numbers, where all values must be included in the answer:

Evaluate multiple answers:

Use "ListAssessment""AllElementsOrderless" to create an assessment function for a list of numbers, where all values must be included in the answer but the order does not matter:

Apply the function to an answer:

Use "Number" comparison in a QuestionObject:

Use "Number" comparison in a QuestionGenerator:

Applications  (1)

Create a QuestionGenerator for reading values from a plot of a random polynomial:

Generate a random instance of the question:

Properties & Relations  (4)

Specify an answer key containing values that differ by less than the tolerance:

The closest value to the answer is chosen:

Assessment will match exact and inexact values, even with zero tolerance:

For an exact match, without numerical approximation applied, consider "ArithmeticResult" or "Expression":

With no Tolerance specified, the tolerance is effectively based on $MachinePrecision: