FreeFEM Documentation on GitHub

stars - forks

Operators

 1 real a = 1. + 2.; 

Works for int, real, complex, string, mesh, mesh3, array.

Increment operator ++

Pre-increment:

 1 2 int i = 0; ++i; 

Post-increment:

 1 2 int i = 0; i++; 

Substraction operator -

 1 real a = 1. - 2.; 

Works for int, real, complex, array.

Decrement operator –

Pre-decrement:

 1 2 int i = 0; --i; 

Post-decrement:

 1 2 int i = 0; i--; 

Multiplication operator *

 1 2 3 real[int] b; matrix A real[int] x = A^-1*b; 

Works for int, real, complex, array, matrix.

Equal operator =

 1 real a = 1.; 

Comparison operator ==

 1 2 3 4 real a = 1.; real b = 1.; cout << (a == b) << endl; 

Comparison operator !=

 1 2 3 4 real a = 1.; real b = 2.; cout << (a != b) << endl; 

Comparison operator <, <=

 1 2 3 4 5 real a = 1.; real b = 2.; cout << (a < b) << endl; cout << (a <= b) << endl; 

Comparison operator >, >=

 1 2 3 4 5 real a = 3.; real b = 2.; cout << (a > b) << endl; cout << (a >= b) << endl; 

Compound operator +=, -=, *=, /=

 1 2 3 4 5 real a = 1; a += 2.; a -= 1.; a *= 3.; a /= 2.; 

Term by term multiplication .*

 1 matrix A = B .* C; 

Division operator /

 1 real a = 1. / 2.; 

Works for int, real, complex.

Term by term division ./

 1 matrix A = B ./ C; 

Remainder from the division %

 1 int a = 1 % 2; 

Works for int, real.

Power operator ^

 1 real a = 2.^2; 

Works for int, real, complex, matrix.

Inverse of a matrix ^-1

 1 real[int] Res = A^-1 * b; 

Warning

This operator can not be used to directly create a matrix, see Matrix inversion.

Transpose operator ‘

 1 real[int] a = b'; 

Works for array and matrix.

Note

For matrix<complex>, the ::freefem’ operator return the Hermitian tranpose.

Tensor scalar product :

$A:B = \sum_{i,j}{A_{ij}B_{ij}}$

C++ arithmetical if expression ? :

a ? b : c is equal to b if the a is true, c otherwise.

Tip

Example with int

 1 2 3 4 5 6 7 8 9 int a = 12; int b = 5; cout << a << " + " << b << " = " << a + b << endl; cout << a << " - " << b << " = " << a - b << endl; cout << a << " * " << b << " = " << a * b << endl; cout << a << " / " << b << " = " << a / b << endl; cout << a << " % " << b << " = " << a % b << endl; cout << a << " ^ " << b << " = " << a ^ b << endl; cout << "( " << a << " < " << b << " ? " << a << " : " << b << ") = " << (a < b ? a : b) << endl; 

The output of this script is:

12 + 5 = 17
12 - 5 = 7
12 * 5 = 60
12 / 5 = 2
12 % 5 = 2
12 ^ 5 = 248832
( 12 < 5 ? 12 : 5) = 5


Tip

Example with real

 1 2 3 4 5 6 7 8 9 real a = qsrt(2.); real b = pi; cout << a << " + " << b << " = " << a + b << endl; cout << a << " - " << b << " = " << a - b << endl; cout << a << " * " << b << " = " << a * b << endl; cout << a << " / " << b << " = " << a / b << endl; cout << a << " % " << b << " = " << a % b << endl; cout << a << " ^ " << b << " = " << a ^ b << endl; cout << "( " << a << " < " << b << " ? " << a << " : " << b << ") = " << (a < b ? a : b) << endl; 

The output of this script is:

1.41421 + 3.14159 = 4.55581
1.41421 - 3.14159 = -1.72738
1.41421 * 3.14159 = 4.44288
1.41421 / 3.14159 = 0.450158
1.41421 % 3.14159 = 1
1.41421 ^ 3.14159 = 2.97069