log

Natural logarithm, element by element.

Category: Mathematics > Elementary Math

Syntax

Y = log(X)

Returns the natural logarithm (base e) of each element of X.

Description

log is the inverse of exp. For a negative real x the principal value is log(abs(x)) + i*pi, so log(-1) is 0 + 3.1416i, which is the identity exp(i*pi) = -1 read backwards. The result is complex as soon as any element needs it.

Other bases follow from the change of base rule: log(x)/log(b), or directly with log2 and log10. For small x, log1p(x) is more accurate than log(1 + x).

Input arguments

X
Numeric array, real or complex.

Output arguments

Y
Array of the same size as X. log(0) is -Inf; the logarithm of a negative real number is complex.

Example

Positive, zero and negative arguments

log([1 exp(1) 10])
log(0)
log(-1)
Output
ans = 1×3

         0    1.0000    2.3026
ans = -Inf
ans = 0.0000 + 3.1416i

Notes

Integer classes such as int8 are not accepted by log in MatLivre.

See also

exp log10 log2 log1p reallog