Function: Difference between revisions
(14 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
=== Built-in trigonometric functions === | === Built-in trigonometric functions === | ||
The following trigonometric functions are known to iMath. They all take exactly one argument. | The following trigonometric functions are known to iMath. They all take exactly one argument. | ||
* <code>cos cosh | * <code>cos cosh arccos arcosh</code> | ||
* <code>sin sinh arsinh | * <code>sin sinh arcsin arsinh</code> | ||
* <code>tan tanh arctan artanh</code> | * <code>tan tanh arctan artanh</code> | ||
* <code>cot coth arccot arcoth</code> | * <code>cot coth arccot arcoth</code> | ||
Line 32: | Line 32: | ||
=== Built-in functions for vectors and matrices === | === Built-in functions for vectors and matrices === | ||
====<code> | ====<code>charpoly ( [[expression]] )</code> ==== | ||
If the expression contains a | If the expression contains a matrix, evaluates to the [https://en.wikipedia.org/wiki/Characteristic_polynomial characteristic polynomial] of the matrix. | ||
====<code>det ( [[expression]] )</code> ==== | |||
If the expression contains a matrix, evaluates to the determinant of the matrix. | |||
====<code>diag ( [[expression]] )</code> ==== | |||
If the expression contains a (row or column) vector, creates a matrix with the elements of the vector in the diagonal. | |||
====<code> | ====<code>hadamard ( [[expression]] ; [[expression]] ; [[expression]] )</code>==== | ||
If the expression | If both first and second expression are vectors or matrices of equal dimensions, calculates their element-wise product (if the third expression is 0), division (if the third expression is 1) or power (if the third expression is 2). Usually, this function is not used directly. Rather, the [[Operator|operators]] <code>.*</code>, <code>./</code> and <code>.^</code> should be used. The element-wise product is also called the [https://en.wikipedia.org/wiki/Hadamard_product_(matrices) Hadamard product]. | ||
====<code> | ====<code>invertmatrix ( [[expression]] )</code> ==== | ||
If the expression contains a | If the expression contains a matrix, inverts the matrix. | ||
====<code> | ====<code>matrixcols ( [[expression]] )</code> ==== | ||
If the expression contains a matrix, | If the expression contains a matrix, counts the number of columns of the matrix. | ||
====<code> | ====<code>matrixrows ( [[expression]] )</code> ==== | ||
If the expression contains a matrix, | If the expression contains a matrix, counts the number of rows of the matrix. | ||
====<code>mindex ( [[expression]] ; [[expression]] ; [[expression]] )</code>==== | ====<code>mindex ( [[expression]] ; [[expression]] ; [[expression]] )</code>==== | ||
If the first expression contains a vector or matrix, evaluates to the element at the given row (second expression) and column (third expression). If the row is a [[wildcard]], a whole column will be returned as a vector. If the column is a [[wildcard]], a whole row will be returned. | If the first expression contains a vector or matrix, evaluates to the element at the given row (second expression) and column (third expression). If the row is a [[wildcard]], a whole column will be returned as a vector. If the column is a [[wildcard]], a whole row will be returned. | ||
====<code> | See also [[Vector and matrix element access]]. | ||
If both expressions are vectors, evaluates to their [https://en.wikipedia.org/wiki/ | |||
====<code>ones ( [[expression]]; [[expression]] )</code> ==== | |||
If the two first expressions evaluate to positive integers, creates a matrix filled with ones. | |||
====<code>rank ( [[expression]] )</code> ==== | |||
If the expression contains a matrix, evaluates to the rank of the matrix. | |||
====<code>reducematrix ( [[expression]]; [[expression]]; [[expression]])</code> ==== | |||
If the first expression is a matrix, and the other expressions evaluate to positive integers, creates a new matrix from the given matrix where the given row and column (second and third expression) are omitted. | |||
====<code>scalprod ( [[expression]] ; [[expression]] )</code>==== | |||
If both expressions are vectors, evaluates to their [https://en.wikipedia.org/wiki/Dot_product scalar product]. The vector product can only be calculated from a column and a row vector of equal length. Any other dimensions will leave the function unchanged. | |||
====<code>solvematrix ( [[expression]] ; [[expression]] ; [[expression]] )</code> ==== | |||
Solves the linear system with the matrix of the first expression, the variables of the second expression and the right-hand side of the third expression. | |||
====<code>submatrix ( [[expression]]; [[expression]]; [[expression]]; [[expression]]; [[expression]])</code> ==== | |||
If the first expression is a matrix, and the other expressions evaluate to positive integers, creates a new matrix from the given matrix containing the elements beginning at the given offset (second and fourth expression) and having the given number of rows and columns (third and fifth expression). Note that row and column count starts at zero! | |||
====<code>tr ( [[expression]] )</code> ==== | |||
If the expression contains a matrix, evaluates to the trace of the matrix. | |||
====<code>transpose ( [[expression]] )</code> ==== | |||
If the expression contains a vector or matrix, evaluates to the transposed vector or matrix. | |||
====<code>ident ( [[expression]] ; [[expression]] )</code> ==== | |||
If the two expressions evaluate to positive integers, creates a [https://en.wikipedia.org/wiki/Identity_matrix unit matrix] of the given dimensions. | |||
====<code> | ====<code>vecprod ( [[expression]] ; [[expression]] )</code>==== | ||
If both expressions are vectors, evaluates to their [https://en.wikipedia.org/wiki/ | If both expressions are vectors, evaluates to their [https://en.wikipedia.org/wiki/Vector_product vector product]. The vector product can only be calculated with two row or column vectors of three components each. Any other dimensions will produce an error. | ||
====<code>vmax ( [[expression]] )</code> ==== | |||
If the expression contains a vector or matrix of which all elements are [[number|numbers]], evaluates to the greatest element. | |||
====<code>vmin ( [[expression]] )</code> ==== | |||
If the expression contains a vector or matrix of which all elements are [[number|numbers]], evaluates to the smallest element. | |||
=== Functions for number display === | === Functions for number display === | ||
Line 68: | Line 106: | ||
=== Functions for sums and products === | === Functions for sums and products === | ||
==== <code>sum ( [[expression]] ; [[expression]] ; [[expression]] )</code> ==== | ==== <code>sum ( [[expression]] ; [[expression]] ; [[expression]] )</code> ==== | ||
Sums the third expression from the lower bound given by the first expression to the upper bound given by the second expression. This function is created by [[SUM FROM ... TO]] | Sums the third expression from the lower bound given by the first expression to the upper bound given by the second expression. This function is created by [[SUM FROM ... TO]]. | ||
=== Functions for conditional evaluation === | === Functions for conditional evaluation === | ||
==== <code>ifelse ( [[condition]] ; [[expression]] ; [[expression]] )</code> ==== | ==== <code>ifelse ( [[condition]] ; [[expression]] ; [[expression]] )</code> ==== | ||
If the condition can be evaluated to a boolean value, evaluates to the first expression if the condition is true, otherwise to the second expression. | If the condition can be evaluated to a boolean value, evaluates to the first expression if the condition is true, otherwise to the second expression. | ||
=== Temperature conversion functions === | |||
The following functions are defined in the abbreviated SI units reference file. They take exactly one argument. | |||
* <code>kelvintocelsius celsiustokelvin</code> | |||
The following functions are defined in the imperial units reference file. They take exactly one argument. | |||
* <code>kelvintofahrenheit fahrenheittokelvin</code> | |||
[[Category:Element]] |
Latest revision as of 18:01, 8 September 2024
iMath has built-in functions and user-defined functions. User-defined functions are created with FUNCTION and FUNCDEF. Function arguments for multi-valued functions are separated by semicolon ;
.
Most functions will try to immediately evaluate themselves. If this is not possible, then the function will remain in the expression where it has been used. In that case it can be evaluated later with the simplification expand.
Built-in trigonometric functions
The following trigonometric functions are known to iMath. They all take exactly one argument.
cos cosh arccos arcosh
sin sinh arcsin arsinh
tan tanh arctan artanh
cot coth arccot arcoth
sec arcsec sech arsech
csc arcsc csch arcsch
Built-in algebraic functions
These functions take exactly one argument.
square sqrt abs fact
(factorial)
Built-in exponential and logarithm functions
These functions take exactly one argument.
exp ln log
(logarithm to basis 10)
Built-in complex-valued functions
These functions take exactly one argument.
re im conjugate
Built-in other functions
These functions take exactly two numbers as arguments.
max(x; y) min(x; y)
This function linearly interpolates between two points given as pairs of (x,y)-values in the first four arguments. The fifth argument is the x-value for which the corresponding y-value should be interpolated.
interpol(x1; y1; x2; y2; x)
Built-in functions for vectors and matrices
charpoly ( expression )
If the expression contains a matrix, evaluates to the characteristic polynomial of the matrix.
det ( expression )
If the expression contains a matrix, evaluates to the determinant of the matrix.
diag ( expression )
If the expression contains a (row or column) vector, creates a matrix with the elements of the vector in the diagonal.
hadamard ( expression ; expression ; expression )
If both first and second expression are vectors or matrices of equal dimensions, calculates their element-wise product (if the third expression is 0), division (if the third expression is 1) or power (if the third expression is 2). Usually, this function is not used directly. Rather, the operators .*
, ./
and .^
should be used. The element-wise product is also called the Hadamard product.
invertmatrix ( expression )
If the expression contains a matrix, inverts the matrix.
matrixcols ( expression )
If the expression contains a matrix, counts the number of columns of the matrix.
matrixrows ( expression )
If the expression contains a matrix, counts the number of rows of the matrix.
mindex ( expression ; expression ; expression )
If the first expression contains a vector or matrix, evaluates to the element at the given row (second expression) and column (third expression). If the row is a wildcard, a whole column will be returned as a vector. If the column is a wildcard, a whole row will be returned.
See also Vector and matrix element access.
ones ( expression; expression )
If the two first expressions evaluate to positive integers, creates a matrix filled with ones.
rank ( expression )
If the expression contains a matrix, evaluates to the rank of the matrix.
reducematrix ( expression; expression; expression)
If the first expression is a matrix, and the other expressions evaluate to positive integers, creates a new matrix from the given matrix where the given row and column (second and third expression) are omitted.
scalprod ( expression ; expression )
If both expressions are vectors, evaluates to their scalar product. The vector product can only be calculated from a column and a row vector of equal length. Any other dimensions will leave the function unchanged.
solvematrix ( expression ; expression ; expression )
Solves the linear system with the matrix of the first expression, the variables of the second expression and the right-hand side of the third expression.
submatrix ( expression; expression; expression; expression; expression)
If the first expression is a matrix, and the other expressions evaluate to positive integers, creates a new matrix from the given matrix containing the elements beginning at the given offset (second and fourth expression) and having the given number of rows and columns (third and fifth expression). Note that row and column count starts at zero!
tr ( expression )
If the expression contains a matrix, evaluates to the trace of the matrix.
transpose ( expression )
If the expression contains a vector or matrix, evaluates to the transposed vector or matrix.
ident ( expression ; expression )
If the two expressions evaluate to positive integers, creates a unit matrix of the given dimensions.
vecprod ( expression ; expression )
If both expressions are vectors, evaluates to their vector product. The vector product can only be calculated with two row or column vectors of three components each. Any other dimensions will produce an error.
vmax ( expression )
If the expression contains a vector or matrix of which all elements are numbers, evaluates to the greatest element.
vmin ( expression )
If the expression contains a vector or matrix of which all elements are numbers, evaluates to the smallest element.
Functions for number display
round ( expression ; expression )
Immediately evaluates to a number rounded to the given number of decimal places, if possible.
ceil ( expression ; expression )
Immediately evaluates to a number rounded up to the given number of decimal places, if possible.
floor ( expression ; expression )
Immediately evaluates to a number rounded down to the given number of decimal places, if possible.
Functions for sums and products
sum ( expression ; expression ; expression )
Sums the third expression from the lower bound given by the first expression to the upper bound given by the second expression. This function is created by SUM FROM ... TO.
Functions for conditional evaluation
ifelse ( condition ; expression ; expression )
If the condition can be evaluated to a boolean value, evaluates to the first expression if the condition is true, otherwise to the second expression.
Temperature conversion functions
The following functions are defined in the abbreviated SI units reference file. They take exactly one argument.
kelvintocelsius celsiustokelvin
The following functions are defined in the imperial units reference file. They take exactly one argument.
kelvintofahrenheit fahrenheittokelvin