Examine several common values of the natural logarithm function.
Calculate the natural logarithm of 1.
ans = 0
The result is 0, which is the x-intercept of the function.
Calculate the natural logarithm of Euler's number, e.
ans = 1
The result is 1 because log is the inverse of exp.
Calculate the natural logarithm of -1.
ans = 0.0000 + 3.1416i
The result is equal to iπ.
Calculate the natural logarithm of 0.
ans = -Inf
The result is -Inf because log is a monotonically increasing function over the real domain .
Define the domain.
X = (0.25:0.25:5)';
Calculate the natural logarithm of the vector, X.
Y = log(X)
Y = -1.3863 -0.6931 -0.2877 0 0.2231 0.4055 0.5596 0.6931 0.8109 0.9163 1.0116 1.0986 1.1787 1.2528 1.3218 1.3863 1.4469 1.5041 1.5581 1.6094
The result is a vector of natural logarithm values.
Plot the function values.
plot(X,Y,'LineWidth',1.5); grid on; xlabel('X'); ylabel('Y'); title('Real-Valued Natural Logarithm');
The real-valued natural logarithm maps values in the domain to the range .
Define a grid of values for the (X,Y) domain.
[X,Y] = meshgrid(-4:0.25:4,-4:0.25:4);
Calculate the complex logarithm on the grid.
Z = log(X+1i*Y);
Make a surface plot of the imaginary portion of the function.
surf(X,Y,imag(Z)) grid on; hold on; title('Principal Branch of Im[$\log(X+iY)$]','Interpreter','latex') xlabel('X'); ylabel('Y'); zlabel('Z'); view(44,42)
On the complex plane, the natural logarithm is a multivalued function that winds around the origin.
To obtain a different branch of the function, add to the Z values.
z2 = Z + 2*pi*1i; surf(X,Y,imag(z2)) title('Two Branches of the Complex Logarithm') view(45,22)
In this plot, the branches are stacked on top of each other and meet along the negative real axis.