Algorithmically generated variables are used to generate random numbers in questions and create multiple permutations of questions from a single template.
You can use either EDU Campus or Maple to generate algorithmic variables. You can use either (or both) types of variables in any question type.
The syntax for a Maple-based variable definition is:
<variable_i>=maple("<Maple_command>");
To define an algorithmic variable in the plain-text script file, specify variable definitions (or other variable control sequences) in the algorithm field.
algorithm=
<variable_definition_1>
...
<variable_definition_n>
@
In the Question Bank Editor, you define variables by directly entering Maple-based variable definitions on the algorithm screen or using the Algorithm Designer.
The following tutorial shows how to convert a static Maple Formula question to an algorithmically-generated question by using variables assigned values by Maple commands.
Consider the following plain-text script question definition, which asks a student to enter an anti-derivative of x^3.
qu.1.1.question=Enter an anti-derivative of x^3.@
qu.1.1.maple=evalb(diff($RESPONSE,x)=x^3)@
qu.1.1.type=formula@
qu.1.1.mode=Maple@
qu.1.1.name=Maple AntiDerivative@
qu.1.1.comment=Any function of the form x^4/4 + C, where C is a constant, is an anti-derivative of x^3.@
qu.1.1.editing=useHTML@
Notes:
This question uses Maple to verify that the derivative of the student response is equal to x^3. This is recommended in place of comparing the student response, which can have an additive constant, with the integral of x^3, that is evalb($RESPONSE=int(x^3,x)).
If the student enters an incorrect response, the system display the value in the comment field. In Maple-graded questions, if there is no comment field, the system returns the message Comment: No feedback provided with this question.
To change this question to an algorithmic question, use the following plain-text script question definition.
qu.1.2.question=Enter an anti-derivative of x^$exponent + ${coeff}x.@
qu.1.2.maple=evalb(diff($RESPONSE,x)=x^$exponent+$coeff*x)@
qu.1.2.type=formula@
qu.1.2.mode=Maple@
qu.1.2.name=Maple AntiDerivative@
qu.1.2.comment=Any function of the form $answer + C, where C is a constant, is an anti-derivative of x^$exponent + ${coeff}x.@
qu.1.2.editing=useHTML@
qu.1.2.algorithm=$exponent=maple("randomize():rand(2..5)()");
$coeff=maple("randomize():rand(2..9)()");
$answer=maple("int(x^$exponent+$coeff*x,x)");
@
Notes:
You must follow the variable naming conventions.
For a list of the guidelines for Maple commands in Maple-based variables, see Algorithm Designer.
The variable $exponent is assigned a value calculated by Maple
using the rand function.
rand() returns a random 12-digit
positive integer
rand(a)() returns a random integer in the range 0
... a-1 (inclusive)
rand(a..b)() returns a random integer in the range a
... b (inclusive)
For information on other Maple commands, see your Maple documentation.
The Maple command:
randomize():
is included so that a different value is generated for each question instantiation. You must include the randomize(): command in every Maple-based variable definition. That is, it is required in the definition of $exponent and $coeff.
The Maple command:
int(x^$exponent,x)
calculates the correct answer, which is displayed using the comment
statement if the student response is incorrect.
The examples in Tutorial 1 can be converted to Maple Syntax questions by changing the type field value from formula to maple. For Maple Syntax questions, it is recommended that you attempt to prevent a student from calculating the correct answer using Maple commands. For more information, see Using Maple Code to Prevent Cheating in Maple Syntax Questions.
For an example plain-text script that defines a Maple question with Maple plotting of the student response, see Plotting a Student Response.
You can also use Maple-based algorithmic variables in other question types.
The following plain-text script defines a Formula question that uses Maple-based variables.
qu.1.3.question=What is the sum of $a and $b?@
qu.1.3.mode=Formula@
qu.1.3.name=Maple-based Variables in Formula@
qu.1.3.answer=$answer@
qu.1.3.editing=useHTML@
qu.1.3.algorithm=$a=maple("randomize():rand(100..200)()");
$b=rint(10,50);
$answer=int($a+$b);
@
Notes:
This question uses both Maple-based (for $a) and EDU random variables (for $b).
See Also:
Maple Formula Question Example Script
Maple-graded Question Type - Overview