log - Natural logarithm - MATLAB (original) (raw)
Syntax
Description
[Y](#bt962gk-1-Y) = log([X](#bt962gk-1-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)
returns
log(abs(z)) + 1i*angle(z)
If you want negative and complex numbers to return error messages rather than return complex results, use reallog instead.
Examples
Show that the natural logarithm of -1 is iπ.
Input Arguments
Input array, specified as a scalar, vector, matrix, multidimensional array, table, or timetable.
Data Types: single
| double
| table
| timetable
Complex Number Support: Yes
Output Arguments
Logarithm values, returned as a scalar, vector, matrix, multidimensional array, table, or timetable.
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
.
Extended Capabilities
Thelog
function fully supports tall arrays. For more information, see Tall Arrays.
Usage notes and limitations:
- When the input value
x
is real, but the output should be complex, simulation ends with an error. To produce the complex result, make the input value complex by passing incomplex(x)
.
Usage notes and limitations:
- When the input value
x
is real, but the output should be complex, simulation ends with an error. To produce the complex result, make the input value complex by passing incomplex(x)
.
The log
function supports GPU array input with these usage notes and limitations:
- If the output of the function running on the GPU can be complex, then you must explicitly specify its input arguments as complex. For more information, see Work with Complex Numbers on a GPU (Parallel Computing Toolbox).
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced before R2006a
The log
function can calculate on all variables within a table or timetable without indexing to access those variables. All variables must have data types that support the calculation. For more information, see Direct Calculations on Tables and Timetables.