Fun cmp

From WeBWorK_wiki
Revision as of 20:10, 18 November 2009 by Aubreyja (talk | contribs) (FunCmp moved to Fun cmp: consistent naming)
Jump to navigation Jump to search

fun_cmp

Description

Creates an answer evaluator which checks expressions defining functions.

Syntax

fun_cmp(function_string, options)
fun_cmp([fun_str1, fun_str2], options)

Params

The first argument is the expression defining the correct function, or one or more expressions placed in square brackets. The options are specified in key => value pairs. (see Options)

Options

Option key Option value Default
var either the number of variables or a reference to an array of variable names ['x', 'y']
limits reference to an array of arrays of limits [[0,1],[0,1]]
mode 'std' (default) (function must match exactly)
'antider' (function must match up to a constant)
'std'
relTol a number indicating the relative tolerance (as a percentage) for checking each point .01 per cent
tol an absolute tolerance for checking error
numPoints the number of points to evaluate the function at 4
params an array of "free" parameters which can be used to adapt the correct answer to the submitted answer. (e.g. ['c'] for a constant of integration in the answer x^3/3 + c ). ['']
maxConstantOfIntegration maximum size of the constant of integration and other free parameters. (prevents numerical overload) 10**100
debug 1 to obtain additional warning messages for debugging, 0 to turn off 0

Returns

One (or more) answer evaluators for expressions defining functions

Examples

* fun_cmp('x^2 +3x') checks that the submitted expression matches this quadratic.
* fun_cmp('t^2- sin(t)', var => 't')
* fun_cmp('t^2 - sin(t)', vars => ['t'], limits => [-4,4]). You can also use limits => [[-4,4]] for consistency
* fun_cmp('x^2 + y^2', vars => ['x', 'y'],
limits => [[-4,4],[-2,6]], numPoints => 10 )
* fun_cmp('x^2 + y^2 + c', vars => ['x', 'y'], params =>['c'],
limits => [[-4,4],[-2,6]], numPoints => 10 ) will match 'x^2 +y^2 + 25'.
* fun_cmp( 'cos(x) + a*e^(-x) + b*e^(2x)', params =>['a', 'b']) will accept a linear family of solutions, e.g. solution set to a linear ODE
* fun_cmp( 'x^2 +sin(c*x)' , params =>['c']) will NOT work. The expressions have to be linear in the parameters (but of course they can be non-linear in the variables such as x).

Notes

The options can be used in any combination that makes sense, and probably some that don't. One exception: reltol and tol cannot be used together.