Why does Matlab use 'log' instead of 'ln'?
159 views (last 30 days)
Okay, I understand that the function for natural logarithm is "log()" and the function for base 10 logarithm is "log10". However, has anyone ever explained why this is the case? I could understand if "ln()" already existed, but it isn't used for anything! I have heard of so many examples of people getting confused or messing up their code because they used "log" instead of "log10", and I just don't understand why Matlab would make it so confusing.
More Answers (2)
John D'Errico on 9 Dec 2015
Edited: John D'Errico on 9 Dec 2015
It is just a design choice, based on a decision probably made by Cleve Moler back in the early 80s. To know more would require clairvoyance, and probably knowledge of what thought were inside the heads of those who wrote FORTRAN, not just MATLAB.
If I had to hazard a complete guess, it might be that much of MATLAB in its beginnings was based on Fortran, and I recall that Fortran used log for the purpose of computing log to the base e. Another vague reason might be that many people MIGHT confuse the function name ln with the word in. Depending on the font used, the two might appear too close together, and thus too likely to cause a bug if you also had a function with that name. Choices like this are completely arbitrary, But it really is impossible to actually KNOW the answer, unless Cleve (or perhaps Loren or another TMW long timer) decides to step in here, IF they truly know the answer themselves.
Yes, I know this is not a terribly satisfying answer, that mainly LOG is probably called LOG because FORTRAN used LOG for the same purpose. But this is really no different from asking why someone was named after their father (or mother), or why they chose any name in particular. Why? Because "your" parents chose that name. That parents chose to name you after your father MAY be a sufficient answer for some people. For others, they might rather think about the basic practice, which seems rooted in tradition, going back many hundreds of years. Why? Because.
Anyway, there is no reason to care since you can trivially write your own function, called ln.
function y = ln(x)
% compute the natural logarithm of the argument x
y = log(x);
I'd do a better job of documentation if I were at all serious of using this code. Or, you can write it an a function handle.
ln = @(x) log(x);
IMHO, the m-file is a better choice, as then it is always on your search path, and it is available inside other functions when you want it.
Shakespeare said it best, via the lips of Juliet.
"What's in a name? That which we call a rose By any other name would smell as sweet."
TastyPastry on 9 Dec 2015
I mean conversely, you could argue why do we use ln() when log() without a specified base could be used as the natural log. There's not really a "why." Though ln()'s origins come from Latin, logarithmus naturali, you could also say that log() without a base implies the natural log. If it really bothers you in Matlab, you can assign ln() as the natural log by using
ln = @log;
in the beginning of your code.