6.22 Details on Using Algorithmic Variables
The Answer Field Evaluation and Requirements
The answer field specifies internal directives, or instructions to the system for how to grade the question. It operates like a command-line statement when processed by the system.
The answer field accepts only values that can be system-evaluated: numbers, formulas, algorithmic variables, or numbers and/or formulas with required physical units.
The system recognizes:
- Equivalent numeric and algebraic expressions
- Equivalent standard physical units
- The ? operator as a representation of a margin of error. The answer:
(3.75 ? 0.05) kg
grades all responses in the range 3.70 to 3.80 kg (inclusive) correct.
Variable definitions must reduce to one of the above.
You can round a variable value to any number of significant digits, and then specify the variable as the answer.
Controlling Display of Numbers within Questions
All random numbers generated by the system from variable definitions are floating-point variables. By default, they are expressed to about 8 significant digits.
To control the display of numeric variables, enclose expressions in an int() statement to make them integers (for example, $m=int(14.5*5);), or in double quotes "" to make them strings (for example, $s="380";).
You can also control the appearance of numeric variables by enclosing random number generating statements and arithmetic operations with decimal(n,(statement)), to express the result to n decimal places, or by using the sig(n,(statement)) structure to express the result to n significant digits.
See Also:
Random Integer Generation rint(n), rint(m, n), rint(m, n, k)
decimal(n, x), sig(n, x), int(x)
Variables within Variable Statements
You can use variables as arguments in variable definition statements.
Since the algorithm generation works linearly, you must define variables before referencing them in other variable definition statements (or control sequences).
Example
qu.3.7.mode=Formula@
qu.3.7.algorithm=
$n=rint(8);
$x=rand(1,10);
$ans=sig($n, $x)
@
qu.3.7.question=
Express the number $x to $n significant places.
@
qu.3.7.answer=$ans@
See Also:
Controlling Answer Tolerance
decimal(n, x), sig(n, x), int(x)
rand(m, n), rand(m, n, k)
Random Integer Generation rint(n), rint(m, n), rint(m, n, k)
Displaying the $ (Dollar Sign) in Questions
The use of the $ is reserved for variable definitions in algorithms in the Maple T.A. question syntax.
To display a $ character in the text of your question, use:
\$
Displaying the Backslash Symbol in Questions
The use of the backslash character is reserved in the Maple T.A. system question syntax. To include a \ character in the text of your question, use:
\\
Text Strings in Variable Statements
Statements defining variables can also include text strings. Strings must be enclosed in double quotes "".
qu.4.1.mode=Formula@
qu.4.1.algorithm=
$animal=switch(rint(2), "cat", "dog");
$mass=if(int(eq("$animal", "cat")), rand(2,15,2), rand(10,30,2));
$velocity=rand(2,5,2)
@
qu.4.1.question=
A $mass kg $animal is running at $velocity m/s. What is its kinetic energy?
@
qu.4.1.answer= (1/2)$mass * $velocity^2
@
In the test for the type of animal in the definition of $mass, it is required that the variable $animal be enclosed in quotes.