Table of Contents

Expression Syntax

Formula editor is used in the following cases:

MagicPlot uses standard IEEE 754 double precision floating-point arithmetic. Double precision floating point takes 8 bytes per number and provides a relative precision of about 16 decimal digits and magnitude range from about 10-308 to about 10+308.

Syntax Highlighting

MagicPlot formula editor highlights expression syntax. It also marks matching brackets and highlights variables:

Image

General Rules

Case Sensitivity

MagicPlot formula translator is generally case sensitive, i.e. you can write sin but not Sin. Note that x and X are different variables. You can use this feature when naming Custom Equation Fit Curve parameters.

Entering Numbers

You can use e or E for scientific notation: 1.45e-3 or 1.45E-3.

Using Spaces and Line Breaks

You can freely insert space characters and line breaks in formula, but do not break function names, numbers, operators. You do not need to enter special characters to indicate line break.

Local variables in expression

You can set a local variables in expression. Use semicolon to separate variable assignments and the result expression: a=5; a*a + 2*a + 1. The expression after the last semicolon is the result expression. The variables are calculated in the present order so you need to assign the variable before usage.

Functions

You can see a list of all available functions and their descriptions in Functions tab in Set Column Formula window and in Help on Functions window which can be opened from menu in calculator window.

MagicPlot uses functions of Java programming language library StrictMath to evaluate sin, cos, exp, etc. These functions are available from the well-known network library netlib as a “Freely Distributable Math Library”, fdlibm package. The same library is widely used in many scientific computing applications.

Special functions (Bessel, Erf, Gamma, Beta) calculation is based on Colt 1.2 library.

Trigonometric Functions

MagicPlot supports all standard trigonometric functions (sin, cos, etc.). All angles are always measured in radians for clarity.

You can use the following functions to convert angles units:

Examples

Constants

The predefined constants are:

Boolean Logic

MagicPlot can interpret boolean logic expressions. Zero is interpreted as false and non-zero values are interpreted as true similarly to C programming language (Note: legacy MagicPlot versions 2.9 and older interpret zero and negative values as false, this was changed in the 3.0 version). You can use simple logical operators which are described below. Use 1 as true and 0 as false.

The conditional function 'if'

The conditional logical function is if(condition, a, b). If condition argument is true (non-zero) it returns the second argument (a), otherwise it returns the third argument (b).

Examples

Equality Checking

You have to be careful if you need to check equality of two values. Due to inaccuracy of computer floating-point calculations the result of evaluation is always approximate. For example, result of sqrt(3)^2 is the number 2.9999999999999996, not exactly 3. The expression sqrt(3)^2 == 3 is false (it returns 0). Keep in mind that for convenience MagicPlot rounds numbers when showing on the screen, so this value will be shown as 3 in table if the number of shown fractional digits in MagicPlot preferences is not big enough.

Generally, if you want to check equality of two values you need to use some equality threshold for relative difference. That is, you should compare the modulus of relative difference of two values a and b with threshold t: if(abs((a-b)/a) < t, …, …).

Examples

Operators

Operator Description Operator Description
+ addition == equal to
- subtraction != not equal to
* multiplication ! logical negation
/ division < less than
% remainder after division > greater than
^ exponentiation <= less than or equal to
| logical or >= greater than or equal to
& logical and

Operations Priority

Operations Precedence Associativity
function() 1 (is evaluated first)
^ 2 Right-to-left
!, - (unary minus) 3
*, /, % 4 Left-to-right
+, - 5 Left-to-right
<, >, <=, >= 6 Left-to-right
==, != 7 Left-to-right
& 8 Left-to-right
| 9 Left-to-right
= (assignment) 10 (is evaluated last) Left-to-right

Operators with lower precedence value are evaluated earlier. You can use brackets to change calculation sequence.

Expression is evaluated left-to-right, excluding repeated exponentiation operator ^. The ^ operator is right-associative like in Fortran language (evaluated right-to-left; note that in general case a^(b^c) ≠ (a^b)^c). Hence a^b^c is evaluated as a^(b^c). The reason for exponentiation being right-associative is that a repeated left-associative exponentiation operation would be less useful: Multiple appearances could (and would) be rewritten with multiplication: (a^b)^c = a^(b*c).

Examples

Comments in formulas

You can insert comments in any formula using /*…*/ notation.

Press Ctrl+/ on Windows/Linux or Cmd-/ on Mac OS to comment selection. Comments can be multi-line. Note that the single line comments using a symbol at the line start are not supported because line breaks are not taken into account in MagicPlot formula syntax.