Mathematics Block

The Mathematics block does a mathematics calculation on its inputs, and outputs the result. You can do a simple mathematics operation with one or two inputs, or enter a formula with up to four inputs.
Choose the Mathematics Operation


Mode Selector
Inputs
Output

Choose the mathematics operation you want to use by selecting a mode with the Mode Selector. After selecting the mode, you can choose values for the inputs. The inputs available will change depending on the mode.
Simple Mathematics Operation Modes
The simple mathematics operation modes calculate the Result with a single mathematics operation using one or two Inputs. These modes are shown in the table below.
ModeInputs UsedOutput Result
Add A, BA + B
Subtract A, BA – B
Multiply A, BA × B
Divide A, BA ÷ B
Absolute Value AA if A ≥ 0 -A if A < 0
The result is always ≥ 0.
Square Root A√A
Exponent A (base), N (Exponent)AN
AdvancedA, B, C, DA + B – C* D
Tips and Tricks
If the input values for a mathematics operation result in an illegal operation, such as division by zero or the square root of a negative number, the output result will be an error value. An error value may be interpreted as zero when used as the input for another programming block.
Example
This program subtracts 50 from the Reflected Light Intensity output of the Colour Sensor block and uses the result as a Power input for a motor. This will make the motor turn backwards when the colour sensor sees something dark and forwards when the sensor sees something light.
Advanced Mode


In the Advanced mode, the Mathematics block can calculate a mathematical expression using up to four inputs and several mathematics operations in one step.

Use Data Wires to connect up to four Numeric values to the A, B, C, and D inputs. Unneeded inputs can be left blank or 0.

Click the Block Text Field at the top of the block to enter the mathematical expression in text form to calculate. The expression can include the inputs by name as “A”, “B”, “C”, and “D”, numeric constants such as “50”, and mathematics symbols such as “+”. You can also use functions from the list displayed and additional parenthesis to change the order of operations.

The result of the expression calculation is output in Result.
Example
In this program the Mathematics block calculates motor power using inputs from the Colour Sensor and two Variables. The Reflected Light Intensity from the Colour Sensor is wired to the A input, and the variables named “Gain” and “Power” are used for B and C. The expression “(A-50)*B+C” in the Mathematics block subtracts 50 from the light intensity, multiplies the result by value of “Gain”, and then adds the value of “Power”.
Inputs and Outputs
The inputs of the Mathematics block provide the values for the mathematics calculation. You can enter the input values directly into the block. Alternatively, the input values can be supplied by Data Wires from the outputs of other Programming Blocks.
InputsTypeNotes
A NumericFirst operand of a simple mathematics operation
B NumericSecond operand of a simple mathematics operation
A NumericBase value in Exponent mode
N NumericExponent value in Exponent mode
C NumericInput for Advanced mode
D NumericInput for Advanced mode
The output of the Mathematics block gives the result of the calculation. To use the output, use a Data Wire to connect it to another Programming Block.
OutputTypeNotes
Result NumericResult of the mathematics calculation
Mathematics
Quick links