### B.7 Simple mathematical functions

The following statements are used to transform data contained in matrices or datasets.

 Syntax Arguments and performed function W = exp(X); W is a matrix with entries equal to the exponentials of the entries of X. The function works element-wise. X must be a matrix or dataset W = log(X); W is a matrix with entries equal to the natural logarithms of the entries of X. The function works element-wise. X must be a matrix or dataset If X contains non-positive entries then the corresponding entries of W are set to nan W = sqrt(X); W is a matrix with entries equal to the square roots of the entries of X. The function works element-wise. X must be a matrix or dataset If X contains negative entries then the corresponding entries of W are set to nan W = abs(X); W is a matrix with entries equal to the absolute values of the entries of X. The function works element-wise. X must be a matrix or dataset W = mod(X, Y); W is a matrix with entries equal to modula of the element-wise division X./Y X must be a matrix or dataset Y must be a matrix or dataset The dimensions of X and Y must be equal W = sin(X); W is a matrix with entries equal to the sines of the entries of X. The function works element-wise. X must be a matrix or dataset W = cos(X); W is a matrix with entries equal to cosines of the entries of X. The function works element-wise. X must be a matrix or dataset W = tan(X); W is a matrix with entries equal to the tangents of the entries of X. The function works element-wise. X must be a matrix or dataset W = asin(X); W is a matrix with entries equal to the arcsines of the entries of X. The function works element-wise. X must be a matrix or dataset If X contains entries outside the interval $\left[-1,1\right]$ then the corresponding entries of W are set to nan W = acos(X); W is a matrix with entries equal to the arccosines of the entries of X. The function works element-wise. X must be a matrix or dataset If X contains entries outside the interval $\left[-1,1\right]$ then the corresponding entries of W are set to nan W = atan(X); W is a matrix with entries equal to the arctangents of the entries of X. The function works element-wise. X must be a matrix or dataset W = inv(X); W is the inverse of X. X must be a square matrix or dataset If X is singular an error is produced W = invpd(X); W is the inverse of X, where X is symmetric and positive deﬁnite. This function works faster and is more precise than the general inv() function, taking advantage of the structure of X. X must be a symmetric and positive-deﬁnite matrix or dataset If X is not positive deﬁnite an error is produced W = det(X); W is an $1\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}1$ matrix with value equal to the determinant of X. X must be a square matrix W = trace(X); W is an $1\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}1$ matrix with value equal to the trace of X. X must be a square matrix W = diag(X); The function’s return value depends on the size of X:$\to$ if X is an $M\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}M$ matrix then W is an $M\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}1$ vector that contains the values on the diagonal of X$\to$ if X is vector of length $M$ then W is a diagonal $M\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}M$ matrix that contains the entries of X on its diagonal. X must be either a square matrix (or dataset) or a vector