The Program Model in Inspera Assessment allows authors to define complex calculations and ensure precision in numerical results for automatically marked questions.
This article explains how to write mathematical equations using infix notation and common operators, and details how to use functions for rounding values.
Calculations in the Program Model
Variables in the Program Model are not just for generating random values; they can also hold full mathematical equations. Equations written in Maxima, and therefore within the Program Model, use infix notation, which is a standard mathematical format where operators are placed between the operands.
Common operators
You can use the following common mathematical operators in your equations:
| + | Addition |
| - | Subtraction |
| * | Multiplication |
| / | Division |
| ^ | Exponentiation |
| ( ) | Parenthesis |
Examples of equations
Here are examples of mathematical equations written using infix notation for the Program Model:
- \(3x^2 + 2x - 5\) =
3x^2 + 2x - 5 \((y + 3) / 2 - 4y\) =
(y + 3) / 2 - 4y\((z + 2) * (z - 3)\) =
(z + 2) * (z - 3)- \(2t * (t + 1)\) =
2*t * (t + 1) - \((x^2 - 1) / (x + 2)\) =
(x^2 - 1) / (x + 2)
Combining Variables in Equations
Any variable previously defined in the Program Model can be included in the equation of another variable, allowing for complex, multi-step calculations.
-
trainA: rand_with_step(30,100,1);trainB: trainA + rand_with_step(5,35,1);combined_speed: trainA + trainB;
The above example
trainAis set as a random value between 30 and 100. Next,trainBis set as a value between 5 to 35 greater thantrainA. Finally,combined_speedis the sum oftrainAandtrainB.
Rounding values
Calculated results or values generated by functions like rand(n.0) (which produces a random floating-point number between 0.0 and n.0) may produce numbers with many decimal places. You can round these values to a specific number of decimal places using the decimalplaces(a, b) function:
a = the value or variable you want to round.
b = the number of decimal places to which a should be rounded.
-
The variable
fruit_weight: rand(5.0);might result in the value 4.69831604812.To make it more manageable you can round it to 2 decimal places in one or two lines. Both options below yield the same result depending on whether you want a specific rounded variable or not.
fruit_weight: rand(5.0);fruit_weight_rounded: decimalplaces(fruit_weight, 2);or
fruit_weight: decimalplaces(rand(5.0), 2);