log
Natural logarithm
Syntax
Description
returns
the natural logarithm ln(x) of
each element in array Y
= log(X
)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
Natural Logarithm of Negative Number
Input Arguments
X
— Input array
scalar | vector | matrix | multidimensional array | table | timetable
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
Y
— Logarithm values
scalar | vector | matrix | multidimensional array | table | timetable
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
Tall Arrays
Calculate with arrays that have more rows than fit in memory.
The
log
function fully supports tall arrays. For more information,
see Tall Arrays.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
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)
.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
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)
.
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
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).
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced before R2006aR2023a: Perform calculations directly on tables and timetables
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.
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)