Main Content

log

Natural logarithm

Syntax

Description

example

Y= log(X)returns the natural logarithmln(x)of each element in arrayX.

Thelogfunction’s domain includes negative and complex numbers, which can lead to unexpected results if used unintentionally. For negative and complex numbersz = u + i*w, the complex logarithmlog(z)returns

log(abs(z)) + 1i*angle(z)

If you want negative and complex numbers to return error messages rather than return complex results, userealloginstead.

Examples

collapse all

Show that the natural logarithm of -1 is i π .

log(-1)
ans = 0.0000 + 3.1416i

Input Arguments

collapse all

Input array, specified as a scalar, vector, matrix, or multidimensional array.

Data Types:single|double
Complex Number Support:Yes

Output Arguments

collapse all

Logarithm values, returned as a scalar, vector, matrix, or multidimensional array.

For positive real values ofXin the interval (0,Inf),Yis in the interval (-Inf,Inf). For complex and negative real values ofX,Y是复杂的。The data type ofYis the same as that ofX.

Extended Capabilities

Introduced before R2006a