|
ANY-maze Help > The ANY-maze reference > The Protocol page > The elements of a protocol > Analysis > Calculations > Setting up a calculation > Defining a calculation's formula Defining a calculation's formula
In briefA calculation's formula is entered into the box shown at the bottom of the calculation's settings page. Specifically, you can define a calculation by:
DetailsFor full details about defining a formula, refer to the sections below:
- Operator precedence and parenthesis
The elements of a formulaA formula can consist of absolute numbers, operators, measure results, and function results.
You can include any number in a formula, provided it has no more than 15 digits including a decimal point. For example, 10, 3.14159, 10000000 are all valid numbers. You can't enter negative numbers directly; for example, -10 is illegal, but you can simply use 0 - 10 to create the same result.
You can include the four standard mathematical operators + - * / in a formula. As you'd expect, these perform operations of addition, subtraction, multiplication and division respectively.
You can include the following mathematical function in a formula:
You can apply multiple functions, one after the other; for example, Sqrt Abs -81. Here the Sqrt function will be performed on Abs -81, and Abs will be performed on -81, so the result will be: abs -81 = 81, Sqrt 81 = 9. A mathematical function can be included in a formula by right clicking, or pressing the Insert key, and selecting Maths functions from the menu which appears.
You can include the comparison operators = > < in a formula. These operators compare the values on either side of them and create result of 1 if the comparison is true and 0 if it is false. This is more useful than it might at first appear, because you can multiply the comparison result by some other value to implement what is effectively an 'if' statement. For example, the formula ((MyValue > 10) * Result1) + ((MyValue < 10) * Result2) would yield a result of Result1 when MyValue is greater than 10 and a value of Result2 when it is less than 10 (you would need to add another clause to cope with the situation when MyValue is equal to 10).
Operator precedence and parenthesis There is no operator precedence as such in ANY-maze formulae; rather, formulae are always calculated from the left to the right. This means, for example, that the result of 20 / 2 + 3 is 13, because 20 / 2 = 10 and 10 + 3 = 13. You can alter this left-to-right calculation order using parenthesis. For example, in the formula 20 / ( 2 + 3 ), ANY-maze will first calculate 2 + 3 and then divide 20 by the result. If parentheses are nested, then calculation starts with the inner-most parentheses. For example, in the formula 20 / ( 5 - ( 2 + 1 ) ), ANY-maze will first calculate 2 + 1, then subtract the result from 5 and finally divide 20 by the answer; i.e. this would be 2 + 1 = 3, 5 - 3 = 2, 20 / 2 = 10.
The result of a measure can be included in a formula by right clicking, or pressing the Insert key, and selecting the appropriate measure from the menu which appears - see figure 1.
Figure 1. To add a measure result to a formula, press the Insert key and choose the measure from the menu which appears.
Measures that don't have numeric results, such as First zone entered, won't be included in the list shown. Measures appear in formulae in green. The values of distance measures will always be in metres, irrespective of the distance units you have chosen in the protocol's analysis options. The same is true of other distance related values, such as speeds, which will always be in units of m/s. This has the advantage that you can change the chosen distance units without affecting the results of your calculations. Note that you specify the units of the result of a calculation when you create it, so if you want the calculation to yield a result in, for example cm, then you can simply write the calculation in an appropriate way - in this case you might need to multiply the final result by 100 to convert it from metres to centimetres. The values of numeric and choice fields are available as measure results, in the case of choice fields, the first available choice is given a value of 0, the second choice a value of 1, the third choice a value of 2, and so on.
A Named value can be included in a formula by right clicking, or pressing the Insert key, and selecting Named values from the menu which appears. Note: If you haven't defined any named values then there will be no entry for Named values in the menu.
To add a function to a formula, you should press the Insert key and choose Add function... from the menu which appears. This will cause the Function wizard to open which will guide you through the necessary steps. After adding a function to a formula, its full definition will be shown in blue. ANY-maze includes the following functions:
Syntax errors in formulasIf you define a formula which doesn't make sense, then ANY-maze will tell you that the formula contains a syntax error. This just means that ANY-maze doesn't understand it. For example, entering 10 * / 2 would generate a syntax error. When a syntax error is detected ANY-maze will highlight, in red, the part of the formula it doesn't understand - this usually makes it very easy to find and correct the mistake. Below are some points to note about the formula syntax:
Editing a formulaYou can edit a formula much like you would text, i.e. by simply moving the cursor to the relevant position and then entering or deleting characters. However, you should note that measure names and function definitions act like a single 'character'.
External changes which affect a formulaAs you may realise, it's possible to make alterations to a protocol which will have side effects on formulas. For example, if a protocol includes the formula: ( Time in the open arms zone / Test duration ) * 100 then deleting the open arms zone will obviously have a rather dramatic effect on the formula! In these cases, ANY-maze will replace parts of a formula which are no longer valid with ???, so our formula would become: ( ??? / Test duration ) * 100 The result of such formulae is considered to be undefined, which means that ANY-maze will simply act as if the formula has no result at all. See also:
© Copyright 2003-2026 Stoelting Co. All rights reserved ANY-maze help topic T0621 |