next up previous contents
Next: Matching Problems Up: Learning to Walk Previous: Sample Problem oldie   Contents

Sample Problem 2

Now that we have done a simple problem with numerical answers, we consider one in which the responses are functions.

Exception to the Rule 1: Note that in the construction below with the ANS function, the variable x is not prefaced by a $.

## Notice that the first occurrence of sin x is between \( and \), and will
## be typeset via LaTeX.  The other occurences of trig functions and
## math symbols will be displayed as plain text.
##
BEGIN_TEXT

This problem demonstrates how you enter function answers into
WeBWorK. 
$PAR 

First enter the function \( \sin\; x \). When entering the
function, you should enter sin(x), but WeBWorK will also accept sin x
or even sinx. If you remember your trig identities, sin(x) =
-cos(x+pi/2), and WeBWorK will accept this or any other function equal
to sin(x), e.g. sin(x) +sin(x)**2+cos(x)**2-1 
$BR
\{ans_rule(35) \}

END_TEXT

## Here we enter the answer as a function of the variable x (the
## default).  Alternate variables are handled shortly.
## Below we have the simplest invocation of the answer function
## function_cmp.  The line could also appear as one line:
## ANS(function_cmp(``sin(x)''));

$ans = "sin(x)";
ANS(function_cmp($ans));



BEGIN_TEXT

$PAR We said you should enter sin(x) even though WeBWorK will also
except sin x or even sinx because you are less likely to make a
mistake.  Try entering sin(2x) without the parentheses and you may be
surprised at what you get. Use the Preview button to see what you get.
WeBWorK will evaluate functions (such as sin) before doing anything
else, so sin 2x means first apply sin which gives sin(2) and then
mutiple by x.  Try it.  
$BR
\{ans_rule(35) \}

END_TEXT


$ans = "sin(2*x)";
ANS(function_cmp($ans));


## Here we play with a function whose independent variable is
## something other than x.
BEGIN_TEXT

$PAR Now enter the function \(2\cos t\).  Note this is a function of
\( t\) and not \( x\). Try entering 2cos x and see what happens.  $BR
\{ans_rule(35) \}

END_TEXT

$ans = "2*cos(t)";
ANS(function_cmp($ans,'t'));

Remark: The function function_cmp actually can take up to 8 arguments. Before going into the details, think about how WeBWorK knows that $ \sin x$ is the same as $ -\cos(x +
\frac{\pi}{2})$. Symbolic checking would be a nightmare, so the convenient solution is compare the values of the real function and the student's proposed answer at several points. If they match, we concede; if not, they try again. The problem is at which points should you test? Obviously, if the domain is unrestricted, the job is easier, but if the domain is constrained, arbitrary points cannot be chosen. That's where all the other options come into play. If not explicitly given, the various parameters have defaults which are defined in the /webwork/system/Global.pm file or the individual course /webwork/courses/course_XYZ/webworkCourse.ph file.

From /webwork_system_html/docs/techdescription/pglanguage/anseval.html, we have

Here the arguments have the following meanings

For example, if your function is $ \sqrt{-1-x}$, you would have to enter something like: function_cmp("sqrt(-1-x)","x",-2,-1). The student's answer (a function) is evaluated at $numOfPoints random points in the half open interval [$llimit,$ulimit). If the result is within $relpercentTol*$correctFunction (with values of absolute value less than $zeroLevel handled the same way as in std_num_cmp) of $correctFunction evaluated at the same points, the student's answer is correct. Allowed functions are listed in Mathematical Functions and Symbols:
/webwork_system_html/docs/techdescription/pglanguage/availableFunctions.html. Syntax, arithmetic, and other errors are reported to the student.


next up previous contents
Next: Matching Problems Up: Learning to Walk Previous: Sample Problem oldie   Contents
Thomas R. Shemanske 2002-03-05