# log

Natural logarithm

## Syntax

• ``Y = log(X)``
example

## Description

example

````Y = log(X)` returns the natural logarithm ln(x) of each element in array `X`.The `log` function's domain includes negative and complex numbers, which can lead to unexpected results if used unintentionally. For negative and complex numbers ```z = u + i*w```, the complex logarithm `log(z)` returnslog(abs(z)) + 1i*atan2(w,u)If you want negative and complex numbers to return error messages rather than return complex results, use `reallog` instead.```

## Examples

collapse all

### Natural Logarithm of Negative Number

Show that the natural logarithm of -1 is .

`log(-1)`
```ans = 0.0000 + 3.1416i```

## Input Arguments

collapse all

### `X` — Input arrayscalar | vector | matrix | multidimensional array

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

Data Types: `single` | `double`
Complex Number Support: Yes

## Output Arguments

collapse all

### `Y` — Logarithm valuesscalar | vector | matrix | multidimensional array

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

For positive real values of `X` in the interval (`0`, `Inf`), `Y` is in the interval (`-Inf`,`Inf`). For complex and negative real values of `X`, `Y` is complex. The data type of `Y` is the same as that of `X`.