Sie befinden sich hier: SIGMA 15 » SIGMA 15 » Simulation » User-defined Function

User-defined Function

Dies ist eine alte Version des Dokuments!


User-defined Function

Besides the above described build-in calculations, SIGMA offers the user to define his own functions to be calculated. These user defined functions are defined in a purpose build mini-language. The results calculated by such user defined functions are treated as any other result and can be viewed in diagrams or as result list.

Manage a User-defined Function

Path: Main menu: Simulation > User-defined functions…



By choosing Simulation, User-defined functions a dialog for managing user defined functions opens. Here a user can create, edit and delete existing user defined functions.

At the top a name for this function and a unit for the return value of the function have to be defined. Once a name is defined it can not be changed in subsequent editing steps.

The middle part of the dialog contains a text field for defining the function. The text in this field is syntax highlighted according to the syntax of user defined functions, for example keywords are colored blue. More to the syntax of user defined functions can be found in the section Define a User-defined Function.

In the lower part, pre-defined variables can be easily chosen and inserted in the text of the user defined function. There are about 150 predefined variables such as calculation results, geometrical data, materials and process parameters that can be used in user defined functions.

By clicking Ok, the given function is tested in view of the syntactical correctness. If there are syntactic errors, these errors will be displayed and the position in the text field will be marked accordingly.

Mathematic Expressions

A mathematic expression represents a single value. In such expressions variables, basic arithmetic operators, predefined functions and brackets can be used. The following enumeration summarizes what may be used in such mathematic expressions with regard to the rules of the user defined functions:

  • Binary operators: There are five binary operators defined. These are the operators for raising the power(^), multiplication(*), division(/), addition(+) and subtraction(-).
  • Unary operator: The unary minus (-) is defined.
  • Brackets: Brackets can be used to parenthesize mathematical expressions.
  • Variables: The user may declare and use own variables. Additionally, there are about 150 predefined variables.
  • Predefined functions: Thirteen predefined functions like sin and the log can be used.
  • User defined functions: already defined functions can be used, too.

For user defined functions some special precedence rules and rules for associativity take place to avoid ambiguities.

Operator Precedence

The operators “*” and “/” have precedence over “+” and “-”.

The power operator ”^” has higher binding strength than the other operators.

Functions have the greatest binding strength.

Parenthesizes expressions are evaluated first.

Associativity

All binary operators are left-associative. That means, terms of more than one operators of the same precedence are evaluated from left to right.

Examples

$a^3+b^2+0.815$ valid expression
$42+(-7)$ valid expression (unary minus)
$\frac{a}{b}/3$ valid expression, evaluated as $\frac{a/b}{3}$ (left-associative)
$\sin(2) \cdot 3.1415$ valid expression, evalutared ast $(\sin 2) \cdot 3.1415$ higher binding-strength of functions
$\sin(2 \cdot 3.1415)$ valid expression
$x^{1/2}$ oder $\sqrt{x}$ valid expression, square-root of x

Logical Expressions

A logical expression represents a single logical value( as ”true” or ”false”). In such an expression comparison operators as well as the logical operators and and or may be used.

Comparison operators compare two (values of) mathematical expressions and return a logical value, which can be further combined by the two defined logical operators. The six comparison operators defined are: Less(<), less-or-equal(⇐), equal(==), greater-or-equal(>=), greater(>) and unequal(!=).

Logical expressions can neither be parenthesized nor their values stored in variables and retrieved later. The use of logical expressions is limited to conditional statements, which are explained in the section Statements.

Examples

$a < 0$ valid expression, true if is $a$ negative
$0.5 < a \land a \leq 1$ true, if is in $a \in (0.5, 1]$
$a \lor b$ invalid, logical values can not be stored in variables
$|0-a| < \varepsilon$ valid, operands are mathematical values

Statements

The above described expression (mathematic and logical) is an inherent part of statements and cannot be used on their own. The user defined functions distinguish between four different statements. Each statement covers only a single line in the language.

Assignments

An assignment binds the value of a mathematical expression to a variable. Therefore, on the left hand side of the assignment sign (=) is the variable and on the right hand side a mathematical expression. The syntax is as follows:

<Identifier> `=´ <mathematical expression>

By using an assignment with an unknown identifier, a variable is created and initialized with the value of the given mathematical expression. The variable can be used later in mathematical expression to retrieve their value.

The identifier has always to start with a letter, but numerals may be contained in the variable identifier.

The value of logical expression cannot be bound to variables!

In the following a few examples to assignments:

$\pi = 3.1415$ valid assignment
$ab2 = a^2 + 2ab + b^2$ valid assignment
$soNicht = (a < 0)$ invalid, $a$ logical value can not be bound to variables
$a = b = 0.0$ invalid, only single assignments are allowed
$2Pi = 2 + \pi$ invalid, the identifier needs to start with a letter

Return

A return statement determines the return-value of the user defined function. The evaluation of the function stops and the function is exited with the given return-value. The syntax is as follows:

`return´ <mathematical expression>

Conditional Statement

An if-then-else statement evaluates a statement dependent on a given condition. This condition is expressed as a logical expression following the keyword if. If the condition holds, the statement following the then-keyword is evaluated, and otherwise the else denoted statement. The else-case is optional. If no else is given, simply the then denoted statement is not evaluated. The syntax is as follows:

`if´ <logical expression> `then´ <statement> [ `else´ <statement> ]

As a simple example the determination of the maximum of two values is shown below:

if a < b        # Wenn a kleiner als b ist
then           # Dann
  max= b       # Ist b das Maximum
else           # Sonst
  max= a       # Ist a das Maximum

Grouping Statements

The keywords begin and end parenthesize a sequence of statements. This group of statements can be evaluated as a single statement, for example in a conditional statement, where one of cases needs more than one single statement to work properly. The syntax is as follows:

`begin´

            <statement 1>
               ...
            <statement n>

`end´''

en/simulation/benutzerdefinierte_funktionen.1768076413.txt.gz · Zuletzt geändert: 2026/01/10 21:20