Main Content

log10

Common logarithm (base 10)

Description

example

Y = log10(X) returns the common logarithm of each element in array X. The function accepts both real and complex inputs. For real values of X in the interval (0, Inf), log10 returns real values in the interval (-Inf ,Inf). For complex and negative real values of X, the log10 function returns complex values.

Examples

collapse all

Examine several values of the base 10 logarithm function.

Calculate the common logarithm of 1.

log10(1)
ans = 0

The result is 0, so this is the x-intercept of the log10 function.

Calculate the common logarithm of 10.

log10(10)
ans = 1

The result is 1 since 101=10.

Calculate the common logarithm of 100.

log10(100)
ans = 2

The result is 2 since 102=100.

Calculate the common logarithm of 0.

log10(0)
ans = -Inf

The result is -Inf since 10-=0.

Create a vector of numbers in the interval [0.5 5].

X = (0.5:0.5:5)';

Calculate the common logarithm of X.

Y = log10(X)
Y = 10×1

   -0.3010
         0
    0.1761
    0.3010
    0.3979
    0.4771
    0.5441
    0.6021
    0.6532
    0.6990

Create two Cartesian grids for X and Y.

[X,Y] = meshgrid(0:0.5:1.5,-2:0.5:2);

Calculate the complex base 10 logarithm log10(X+iY) on the grid. Use 1i for improved speed and robustness with complex arithmetic.

Z = log10(X + 1i*Y)
Z = 9×4 complex

   0.3010 - 0.6822i   0.3142 - 0.5758i   0.3495 - 0.4808i   0.3979 - 0.4027i
   0.1761 - 0.6822i   0.1990 - 0.5425i   0.2559 - 0.4268i   0.3266 - 0.3411i
   0.0000 - 0.6822i   0.0485 - 0.4808i   0.1505 - 0.3411i   0.2559 - 0.2554i
  -0.3010 - 0.6822i  -0.1505 - 0.3411i   0.0485 - 0.2014i   0.1990 - 0.1397i
     -Inf + 0.0000i  -0.3010 + 0.0000i   0.0000 + 0.0000i   0.1761 + 0.0000i
  -0.3010 + 0.6822i  -0.1505 + 0.3411i   0.0485 + 0.2014i   0.1990 + 0.1397i
   0.0000 + 0.6822i   0.0485 + 0.4808i   0.1505 + 0.3411i   0.2559 + 0.2554i
   0.1761 + 0.6822i   0.1990 + 0.5425i   0.2559 + 0.4268i   0.3266 + 0.3411i
   0.3010 + 0.6822i   0.3142 + 0.5758i   0.3495 + 0.4808i   0.3979 + 0.4027i

Input Arguments

collapse all

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

Data Types: single | double | table | timetable
Complex Number Support: Yes

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Version History

Introduced before R2006a

expand all

See Also

| | | | | | | |