MATLAB Answers

Why does Matlab use 'log' instead of 'ln'?

992 views (last 30 days)
David K
David K on 9 Dec 2015
Edited: John D'Errico on 9 Dec 2015
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.

Accepted Answer

Image Analyst
Image Analyst on 9 Dec 2015
Probably because most other languages follow that same naming convention. Not sure why, just historical I guess.
  3 Comments
Star Strider
Star Strider on 9 Dec 2015
If I remember correctly, early versions of MATLAB were written in FORTRAN because the versions of BLAS and LAPAC (that MATLAB was created to facilitate the use of) were — as was everything else at the time — written in FORTRAN.

Sign in to comment.

More Answers (2)

John D'Errico
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
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.
  2 Comments
Walter Roberson
Walter Roberson on 9 Dec 2015
Computers (except some obscure devices) use binary for their numeric system, so by that reasoning, log() should be log base 2.
For whatever it is worth:
Maple offers both ln(x) and log(x) for the natural logarithm, and log10(x), and log[b](x) for log base b.
Mathematica offers Log[x] for natural logarithm, and Log10[x] and Log2[x], and Log[b,x] for log base b.
In C, C++, Fortran, Java, and LISP, log() is natural logarithm. In COBOL, LOG() is natural logarithm.
But at least in Smalltalk, log is log 10.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!