Skip to content
Classroom

Function

Answer type: numfunc

The student types a function expression. It is graded by evaluating both their answer and the correct one at sample points across a domain, so any equivalent form passes.

This is a typed answer, not a graphing input

Earlier versions of this page described the Function type as "graph drawing". It is not — the student types a formula. For a student-drawn graph, see Drawing.

The minimum

Common Control:

$answer = "x^2 - 4"
$variables = "x"

Options

Variable Effect
$answer the correct function — required
$variables the variable names the expression may use
$domain the interval sampled during comparison
$abstolerance / $reltolerance tolerance at each sample point
$requiretimes format restriction: comma-separated pairs of a symbol and a count rule, e.g. "(,=0" (no parentheses) or "*,>=1"; a correct function that breaks the rule scores 0
$partialcredit alternative answers worth partial credit, as answer/credit pairs: array("3x-6", .5) or "3x-6,.5" (ignored for list answers)
$answerformat accepted-format flags
$formatfeedbackon when set, a correct function rejected only by $requiretimes or the sameform format is flagged as "right answer, wrong format" (it still scores 0)
$ansprompt, $answerboxsize, $hidepreview input box

$variables

Declare every variable the answer may contain. A multivariable answer lists them all:

$variables = "x,y"

$domain

The interval over which the two functions are compared; the default is -10,10. Test points where your $answer is undefined are skipped, so sqrt(x) or ln(x) on the default window does not by itself mark a correct answer wrong. The risk runs the other way: when your $answer is defined where a student's equivalent form is not, those points count against the student — on the default window $answer = "ln(x^2)" marks 2ln(x) wrong, and $answer = "x" marks sqrt(x)^2 wrong. Set $domain to the interval the question is about whenever an equivalent form could be undefined somewhere in the default window.

$answer = "ln(x)"
$variables = "x"
$domain = "0.1,10"

Example

Common Control — setup:

$a = nonzerorand(-5, 5)
$h = nonzerorand(-4, 4)
$fn = "$a*(x - $h)^2"

Question Text:

<p>Write the parabola with vertex `($h, 0)` and leading coefficient `$a`.</p>

Common Control, continued — answer and options:

$answer = $fn
$variables = "x"
$domain = "-10,10"
$ansprompt = "f(x) = "

See Also

  • Calculated — a numeric answer the student may type as an arithmetic expression such as 3/4 or sqrt(2) (no variables)
  • Drawing — when the student draws the graph
  • Intervals — domain and range answers