# Algorithm Documentation

This article gives a brief introduction to commonly used features in the algorithm section of the question editor. For more detail, see this article from Mobius's help documentation.

When building a question in Mobius two different input fields are available: the Question text field (with familiar image and video input, html editing capabilities and formatting options), the algorithm field, a Custom CSS field, and a Feedback Field. To view the Algorithm field simply click “Algorithm” to expand it into view.

The Question Text field will house your actual question, but it is just a display – think of the brains of the question being the algorithm.

Getting the two to talk to each other involves variables (defined with “$” symbol).

When $variable is in the question field it will display as the value defined by the algorithm.

For example: if in the question text a length is displayed as equal to $L (ie length = $L in) and in the algorithm $L = 7, the question field will display 7 (ie length = 7 in).

Responses from the student are received through an item called a Response Area – variables are used here as well to link the responses to the algorithms.

## Introduction to Algorithm Code

Algorithm code (Formally documented as MAPLE TA) is a programming language that follows specific rules and constructs – for instance the symbol “$” declares a variable. Functions can be called (like in excel) and constants like pi are recognized. Breaking these rules will trigger a built in debugger that will attempt to tell you where the error in the code is located.

Don’t stop reading!! This is simpler than it sounds.

## A First Question

First let’s look a little closer at the multiplication problem: a x b = c. The question might read something like “Find the product of a and b:” The instructor wants all these values to change and then c to change accordingly.

- First write the question to reflect the variables: reword as “Find the product of $a and $b:” This will now link the question display to the algorithm.
- Build the variable in the algorithm field
- do this the same was as in the question field with the “$” symbol (ie $a and $b)

- Set the variables equal to a random number between 1 and 6
- $a=range(1,6);
- $b=range(1,6);

Whoa! What just happened? Programming!! Look a little closer at 3.a: First we told Mobius which algorithm we were working with by using “$a”, next we set it equal to something using the “=” operator. Finally we used a function to find a random integer based on some conditions. In this case a random integer between 1 and 6 using the range() function. Don’t forget to close your code lines with the “;” semi-colon operator.

Now when we preview the question, a and b will randomly be changed to values between 1 and 6.

Now for the answer – c.

Back in our question text let’s add a response area and then select the numeric response. In the numeric part field (this is what would be the question answer) simply create a variable called $answer to link it to the algorithm.

Now in the algorithm field, create a variable called $answer and then set it equal to a x b with the “=” operator and the a and b variable names and the “*” multiplication operator.

Your code might look something like this:

$a=range(1,6); $b=range(1,6); $ans=$a*$b;

Now in previewing the question answers can be entered and grading them will show that the answer changes with a and b.

Great! You are now a master of the algorithm feature in Mobius.

## The Algorithm Designer

Mobius has a quick wizard for creating variables so we don’t have to remember all the syntax. Expand the red “Show Designer” link under the Algorithm heading to show the wizard. After entering the needed data and hitting “Add” Mobius will automatically generate the syntax at the point where the cursor is in the algorithm field.

## Useful Algorithmic Functions

### R-Int

rint(x)

Rint returns a random integer between 0 and the argument given (x).

### Switch

switch(i,1,2,3,4,5,6…)

Switch essentially means “pick x from list”. The first argument is the index of which item to pick ( i ) and the following arguments are the list.

### Range

range(x,y,z)

Range returns a random number greater than x and less than y in steps of z. ie range(15,30,5) would return either 15, 20, 25 or 30

### Maple

maple(“string entry”)

Mobius has access to the Maple programming engine when greater complexity of code is needed or wanted. The string entry argument is simply maple code that will be evaluated with the Maple engine and return a value.

## 0 Comments

## Add your comment