Mathematical functions

The functions described below implement common mathematical functions which can be applied element-wise to the elements of a matrix such as cos, sqrt, etc.

abs

template<typename S>
auto castor::abs(matrix<S> const &X)

Absolute value.

abs(X) is the absolute value of the elements of X. When X is complex, abs(X) is the complex modulus (magnitude) of the elements of X.

matrix<> X = {{-1,-2,-3},{4,5,6}};
matrix<> Y = abs(X);
disp(Y);

See angle, sign.

acos

template<typename S>
auto castor::acos(matrix<S> const &X)

Inverse cosine, result in radians.

acos(X) is the arccosine of the elements of X.

matrix<> X = {-1,0,1};
matrix<> Y = acos(X);
disp(Y);

See acosd, cos.

acosd

template<typename S>
auto castor::acosd(matrix<S> const &X)

Inverse cosine, result in degrees.

acosd(X) is the arccosine of the elements of X.

matrix<> X = {-1,0,1};
matrix<> Y = acosd(X);
disp(Y);

See acos, cosd.

acosh

template<typename S>
auto castor::acosh(matrix<S> const &X)

Inverse hyperbolic cosine.

acosh(X) is the inverse hyperbolic cosine of the elements of X.

matrix<> X = {{1,2,3},{4,5,6}};
matrix<> Y = acosh(X);
disp(Y);

See cosh.

angle

template<typename S>
auto castor::angle(matrix<S> const &X)

Phase angle.

angle(X) returns the phase angles, in radians, of a matrix with complex elements.

matrix<> A = {{1,0,-1},{1,0,-1}};
matrix<> B = {{0,0,0},{1,1,1}};
auto     X = A + M_1I*B;
matrix<> Y = angle(X);
disp(Y);

See abs.

asin

template<typename S>
auto castor::asin(matrix<S> const &X)

Inverse sine, result in radians.

asin(X) is the arcsine of the elements of X.

matrix<> X = {-1,0,1};
matrix<> Y = asin(X);
disp(Y);

See sin, asind.

asind

template<typename S>
auto castor::asind(matrix<S> const &X)

Inverse sine, result in degrees.

asind(X) is the arcsine of the elements of X.

matrix<> X = {-1,0,1};
matrix<> Y = asind(X);
disp(Y);

See sind, asin.

asinh

template<typename S>
auto castor::asinh(matrix<S> const &X)

Inverse hyperbolic sine.

asinh(X) is the inverse hyperbolic sine of the elements of X.

matrix<> X = {{1,2,3},{4,5,6}};
matrix<> Y = asinh(X);
disp(Y);

See sinh.

atan

template<typename S>
auto castor::atan(matrix<S> const &X)

Inverse tangent, result in radians.

atan(X) is the arctangent of the elements of X.

matrix<> X = {-1,0,1};
matrix<> Y = atan(X);
disp(Y);

See tan, atand.

atand

template<typename S>
auto castor::atand(matrix<S> const &X)

Inverse tangent, result in degrees.

atand(X) is the arctangent of the elements of X.

matrix<> X = {-1,0,1};
matrix<> Y = atand(X);
disp(Y);

See tand, atan.

atanh

template<typename S>
auto castor::atanh(matrix<S> const &X)

Inverse hyperbolic tangent.

atanh(X) is the inverse hyperbolic tangent of the elements of X.

matrix<> X = {{1,2,3},{4,5,6}};
matrix<> Y = atanh(X);
disp(Y);

See tanh.

ceil

template<typename S>
auto castor::ceil(matrix<S> const &X)

Round towards plus infinity.

ceil(X) rounds the elements of X to the nearest integers towards infinity.

matrix<> X = {{1,2,3},{4,5,6}};
matrix<> Y = ceil(X+0.5);
disp(Y);

See floor, round.

conj

inline matrix<float> castor::conj(matrix<float> const &A)
inline matrix<double> castor::conj(matrix<double> const &A)
template<typename S>
auto castor::conj(matrix<S> const &X)

Complex conjugate.

conj(X) is the complex conjugate of X. For a complex matrix X, conj(X) = real(X) - M_1i*imag(X).

matrix<> A = {1,0,-1};
matrix<> B = {-1,0,1};
auto     X = A + M_1I*B;
auto     Y = conj(X);
disp(Y);

See real, imag.

cos

template<typename S>
auto castor::cos(matrix<S> const &X)

Cosine of argument in radians.

cos(X) is the cosine of the elements of X.

matrix<> X = {0,M_PI/2,M_PI,-M_PI/2};
matrix<> Y = cos(X);
disp(Y);

See acos, cosd.

cosd

template<typename S>
auto castor::cosd(matrix<S> const &X)

Cosine of argument in degrees.

cosd(X) is the cosine of the elements of X.

matrix<> X = {0,90,180,-90};
matrix<> Y = cosd(X);
disp(Y);

See acosd, cos.

cosh

template<typename S>
auto castor::cosh(matrix<S> const &X)

Hyperbolic cosine.

cosh(X) is the hyperbolic cosine of the elements of X.

matrix<> X = {{1,2,3},{4,5,6}};
matrix<> Y = cosh(X);
disp(Y);

See acosh.

deg2rad

template<typename T>
auto castor::deg2rad(T x)
template<typename T>
matrix<T> castor::deg2rad(matrix<T> const &X)

Convert angles from degrees to radians.

deg2rad(X) converts angle units from degrees to radians for each element of X.

matrix<> X = {0,90,180,-90};
matrix<> Y = deg2rad(X);
disp(Y);

See rad2deg.

exp

template<typename S>
auto castor::exp(matrix<S> const &X)

Exponential.

exp(X) is the exponential of the elements of X, e to the X. For complex Z = X + M_1i*Y, exp(Z) = exp(X) * (cos(Y) + M_1i*sin(Y)).

matrix<> A = {1,1,1};
matrix<> B = {-M_PI,0,M_PI};
auto     X = A + M_1I*B;
auto     Y = exp(X);
disp(Y);

See log, log10.

floor

template<typename S>
auto castor::floor(matrix<S> const &X)

Round towards minus infinity.

floor(X) rounds the elements of X to the nearest integers towards minus infinity.

matrix<> X = {{1,2,3},{4,5,6}};
matrix<> Y = floor(X+0.5);
disp(Y);

See ceil, round.

imag

inline matrix<float> castor::imag(matrix<float> const &A)
inline matrix<double> castor::imag(matrix<double> const &A)
template<typename S>
auto castor::imag(matrix<S> const &X)

Complex imaginary part.

imag(X) is the imaginary part of X.

matrix<> A = {1,0,-1};
matrix<> B = {-1,0,1};
auto     X = A + M_1I*B;
auto     Y = imag(X);
disp(Y);

See real, conj, angle, abs.

log

template<typename S>
auto castor::log(matrix<S> const &X)

Natural logarithm.

log(X) is the natural logarithm of the elements of X.

matrix<> X = {-1,0,1,std::exp(1)};
auto     Y = log(X);
disp(Y);

See log2, log10, exp.

log2

template<typename S>
auto castor::log2(matrix<S> const &X)

Common (base 2) logarithm.

log2(X) is the base 2 logarithm of the elements of X.

matrix<> X = {-1,0,1,2,4};
auto     Y = log2(X);
disp(Y);

See log, log10, exp.

log10

template<typename S>
auto castor::log10(matrix<S> const &X)

Common (base 10) logarithm.

log10(X) is the base 10 logarithm of the elements of X.

matrix<> X = {-1,0,1,10,100};
auto     Y = log10(X);
disp(Y);

See log, log2, exp.

pow

template<typename R, typename S>
auto castor::pow(R x, matrix<S> const &Y)
template<typename R, typename S>
auto castor::pow(matrix<R> const &X, S y)
template<typename R, typename S>
auto castor::pow(matrix<R> const &X, matrix<S> const &Y)

Power of argument.

pow(A,B) denotes element-by-element powers. A and B must have compatible sizes. In the simplest cases, they can be the same size or one can be a scalar. Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are either the same or one of them is 1.

matrix<> A = {-2,-1,0,1,2};
matrix<> B = {-2,-1,0,1,2};
matrix<> C = pow(A,B);
matrix<> D = pow(A,2);
disp(C);
disp(D);

See exp, log.

rad2deg

template<typename T>
auto castor::rad2deg(T x)
template<typename T>
matrix<T> castor::rad2deg(matrix<T> const &X)

Convert angles from radians to degrees.

rad2deg(X) converts angle units from radians to degrees for each element of X.

matrix<> X = {0,M_PI/2,M_PI,-M_PI/2};
matrix<> Y = rad2deg(X);
disp(Y);

See deg2rad.

real

inline matrix<float> castor::real(matrix<float> const &A)
inline matrix<double> castor::real(matrix<double> const &A)
template<typename S>
auto castor::real(matrix<S> const &X)

Complex real part.

real(X) is the real part of X.

matrix<> A = {1,0,-1};
matrix<> B = {-1,0,1};
auto     X = A + M_1I*B;
auto     Y = real(X);
disp(Y);

See imag, conj, angle, abs.

round

template<typename S>
auto castor::round(matrix<S> const &X)

Rounds towards nearest decimal or integer.

round(X) rounds each element of X to the nearest integer.

matrix<> X = {{1,2,3},{4,5,6}};
matrix<> Y = round(X+X/10);
disp(Y);

See floor, ceil.

sign

template<typename S>
auto castor::sign(matrix<S> const &X)

Signum function.

For each element of X, sign(X) returns 1 if the element is greater than zero, 0 if it equals zero and -1 if it is less than zero. For the nonzero elements of complex X, sign(X) = X ./ ABS(X).

matrix<> X = {{-1,-2,0},{3,4,0}};
matrix<> Y = sign(X);
disp(Y);

See abs.

sin

template<typename S>
auto castor::sin(matrix<S> const &X)

Sine of argument in radians.

sin(X) is the sine of the elements of X.

matrix<> X = {0,M_PI/2,M_PI,-M_PI/2};
matrix<> Y = sin(X);
disp(Y);

See asin, sind.

sind

template<typename S>
auto castor::sind(matrix<S> const &X)

Sine of argument in degrees.

sind(X) is the sine of the elements of X.

matrix<> X = {0,90,180,-90};
matrix<> Y = sind(X);
disp(Y);

See asind, sin.

sinh

template<typename S>
auto castor::sinh(matrix<S> const &X)

Hyperbolic sine.

sinh(X) is the hyperbolic sine of the elements of X.

matrix<> X = {0,1,2,3};
matrix<> Y = sinh(X);
disp(Y);

See asinh.

sqrt

template<typename S>
auto castor::sqrt(matrix<S> const &X)

Square root.

sqrt(X) is the square root of the elements of X.

matrix<> X = {-1,0,1,2,4};
auto     Y = sqrt(X);
disp(Y);

See pow.

tan

template<typename S>
auto castor::tan(matrix<S> const &X)

Tangent of argument in radians.

tan(X) is the tangent of the elements of X.

matrix<> X = {0,M_PI/2,M_PI,-M_PI/2};
matrix<> Y = tan(X);
disp(Y);

See atan, tand.

tand

template<typename S>
auto castor::tand(matrix<S> const &X)

Tangent of argument in degrees.

tand(X) is the tangent of the elements of X.

matrix<> X = {0,90,180,-90};
matrix<> Y = tand(X);
disp(Y);

See atand, tan.

tanh

template<typename S>
auto castor::tanh(matrix<S> const &X)

Hyperbolic tangent.

tanh(X) is the hyperbolic tangent of the elements of X.

matrix<> X = {0,1,2,3};
matrix<> Y = tanh(X);
disp(Y);

See atanh.