%% Plot of Complex Base 10 Logarithm
% Define a grid of values for the (X,Y) domain.

[X,Y] = meshgrid(-5:0.25:5,-5:0.25:5);

%
% Calculate the complex base 10 logarithm on the grid.

Z = log10(X+1i*Y);

%
% Make a surface plot of the imaginary portion of the function.

figure
surf(X,Y,imag(Z))
grid on
hold on
title('Principal Branch of Im[$\log_{10}(X+iY)$]','Interpreter','latex')
xlabel('X')
ylabel('Y')
zlabel('Z')
view(44,42)

% On the complex plane, the common logarithm is a multivalued function that winds around the origin.
%
% Since
% \log_{10}(X) = \frac{\log(X)}{\log(10)},
% you can obtain another branch of the function by adding 2 \pi i/ \log(10) to the Z values.

z2 = Z + 2*pi*1i/log(10);
surf(X,Y,imag(z2))
title('Two Branches of the Complex Base 10 Logarithm')
view(45,22)
hold off

% In this plot, the branches are stacked on top of each other and meet along the negative real axis.
% Copyright 2015 The MathWorks, Inc.