GFem language documentation -- 3.4.1 Functions and scalars

Up: 3.4 Functions
Next: 3.4.2 Building functions

### 3.4.1 Functions and scalars

Functions are either read or created.

- Functions can be read from a file if its values at the vertices of the triangulation are stored in text format. (Open a .dta example with a text editor to see the format).
- Functions can be created by executing a program. An instruction like `f=x*y` really means that f(x,y)=x*y

  for all `x` and `y`. Here `x` and `y` refer to the coordinates in the domain represented by the triangulation.

- Functions can be created with other previously defined functions such as in `g=sin(x*y); f=exp(g);` .
- Four other variables can be used besides `x, y, iv, t` : `nx, ny, ib, region`.

Most usual functions can be used:

    max, min, abs, atan, sqrt,
    cos, sin, tan, acos, asin, one,
    cosh, sinh, tanh, log, exp

`one(x`y<0)+ for instance means `1` if `x`y<0+ and `0` otherwise.

Operators:

    and, or, < , <=, < , >=, ==, +, -, *, /, ^
    x^2 means x*x

Functions created by a program are displayed only if the key word `plot()` or `plot3d()` is used ( here `plot(f)` ).

Derivatives of functions can be created by the keywords `dx()` and `dy()` .

Unless `precise` is set, they are interpolated so the results is also continuous piecewise linear (or discontinuous when precise is set). Similarly the convection operator `convect(f,u1,u2,dt)` defines a new function which is approximately

Scalars are also helpful to create functions. Since no data array is attached to a scalar the symbol `:=` is useful to create them, as in

     a:= (1+sqrt(5))/2;
     f= x*cos(a*pi*y);

Here `f` is a function, `a` is a scalar and `pi` is a (predefined) a scalar.

It is possible to evaluate a function at a point as in `a:=f(1,0)` Here the value of `a` will be `1` because `f(1,0)` means `f` at `x=1` and `y=0` .