WebRespond: Variable and Equation Support

With the introduction of the computation question WebRespond can insert variables into displayed text and use those variables to calculate answers.  The following describes how to use variables and what computation capabilities are available.

Variables

The tags needed to introduce variables to a computation question are given in the documentation for the Question File.  These tags allow you to define the name of the variable,<Variable>; the valid ranges of the variable, <Bounds>; the number of significant digits, <Sigfigs>; and the units for the variable, <Vunits>.  The following is an example where two variables, length and time, are defined.
<Variable>length</Variable>
<Bounds>-20.0,20.0</Bounds>
<Sigfigs>3</Sigfigs>
<Vunits>mi</Vunits>
<Variable>time</Variable>
<Bounds>0.2,5.0</Bounds>
<Bounds>-0.2,-4.0</Bounds>
<Sigfigs>5</Sigfigs>
<Vunits>hr</Vunits>
Given the example above a possible value generated for the length could be -1.45 mi.  This value falls between -20 and +20, is reported to three significant digits and has units of miles.  A possible value for time could be 4.1532 s.  This value falls between -4.0 and -0.2 or between 0.2 and 5.0, is reported to five significant digits and has units of seconds.  You notice that two bounds are given for time.  This makes it possible to exclude problematic conditions (dividing by zero) when calculating equations.

The bounds tag does not need to use decimal values, but can use integer and scientific notation forms.  The restriction on the bounds tag is that it must contain an ordered pair of numbers separated by a comma.  Therefore, decimal values must use a period rather than a comma when representing their numbers in this tag.  The following uses of the bounds tag are all equally valid.

<Bounds>1, 15</Bounds>
<Bounds>1.5e-15, 1.5e-12</Bounds>
<Bounds>-25, 2.5e1</Bounds>
One additional tag is available when working with variables.  It is the granularity tag, <Granularity>, and it is used to indicate how close a variable is to zero before it is set equal to zero.  Lets use the following variable definition to generate a value.
<Variable>x</Variable>
<Bounds>-99, 99</Variable>
<Sigfigs>2</Sigfigs>
This definition may be used to generate an integer value in the range indicated.  However, it is possible that x could equal 0.000000034.  By default the granularity is set to 0.01.  Therefore, this generated value would be represented as 0.  With this definition is is still possible to get a number such as 0.011.  This might be acceptable; however, if the granularity tag is set to 1,
<Granularity>1.0</Granularity>
then any value smaller than 1.0 would be assigned a value of 0. To use a variable in a question's text the variable name must be preceded by an & and terminated with a ;. Therefore, using the variables defined above we may have the following text.
A car travels &length; in &time;.  What is the speed of the car?
When this text is displayed it would appear as
A car travels -1.45 mi in 4.1532 s.  What is the speed of the car?

Equations

Equations are defined in the answer tag of the computation question. The equation can use any algebraic expression as well as predefined functions. Acceptable algebraic operators are the following (+, -, *, /, ^) and they correspond to addition, subtraction, multiplication, division, and exponentiation respectively. Priority of operations are observed with calculations proceeding from left to right. In order to supersede the priority of operation parenthesis can be used.
Functions can also be used in algebraic expressions. Functions are preceded by an @ and are terminated with a set of parenthesis, (). Inside the parenthesis is any appropriate value to be passed to the function. The following functions are supported.
 
Function Name Usage Argument
Sine @sin( angle ) angle - Value given in radians
Arc Sine @asin( arg ) arg - Value between -1 and 1
Cosine @cos( angle ) angle - Value given in radians
Arc Cosine @acos( arg ) arg - Value between -1 and 1
Tangent @tan( angle ) angle - Value given in radians
Arc Tangent @atan( arg ) arg - Any value possible
Natural log @ln( arg ) arg - Value greater than 0
Natural Exponential ( ex ) @exp( arg ) arg - Any value possible
Logarithm base 10 @log( arg ) arg - Value greater than 0
Square Root @sqrt( arg ) arg - Value greater then 0
Factorial (x!) @fact( arg ) arg - If not already, will be made a positive integer

Variables can be used in equations as described above.  There are also two defined variables pi and exp that always return the same value.  Pi is defined as 3.1415927 and is accessed by using &pi;Exp is defined as 2.7182818 and is accessed by using &exp;.

Note:

&exp; is different than @exp(); however, they can be used to generate the same result.  &exp;^2 is the same as @exp( 2 ).

Another equivalence is with the square root where @sqrt( 16 ) can be replaced with 16^0.5 or 16^(1/2).

Example:

At the beginning of this page we defined the variables length and time.
<Variable>length</Variable>
<Bounds>-20.0,20.0</Bounds>
<Sigfigs>3</Sigfigs>
<Vunits>mi</Vunits>
<Variable>time</Variable>
<Bounds>0.2,5.0</Bounds>
<Bounds>-0.2,-4.0</Bounds>
<Sigfigs>5</Sigfigs>
<Vunits>hr</Vunits>
These variables were accesses to generate a question asking for the speed.
A car travels &length; in &time;.  What is the speed of the car?
The answer to this question will change with the values generated for length and time.  By defining the answer as an equation this problem can be avoided.  Within the computation question an answer field is provided with the following code.
<Label>speed</Label>

<Answer>&length;/&time;</Answer>

<Mode>equation</Mode>

<Aunits>mi/hr</Aunits>

<Accuracy>0.01</Accuracy>
A text field is provided which appears as follows (except it will all be on one line).
Speed: 
mi/hr
If the value of length is -1.45 and the time is 4.1532, then the generated answer for the speed is -0.349.  The student's answer will be consider correct if it falls within 1% of this value as indicated by the accuracy tag.  The mode tag needs to be set to equation otherwise the answer is considered to be literally the text "&length;/&time;".