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

조회 수: 187 (최근 30일)
David K
David K 2015년 12월 9일
편집: John D'Errico 2015년 12월 9일
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.

채택된 답변

Image Analyst
Image Analyst 2015년 12월 9일
Probably because most other languages follow that same naming convention. Not sure why, just historical I guess.
  댓글 수: 3
David K
David K 2015년 12월 9일
Barring any other inputs, this does seem like a plausible reason.
Star Strider
Star Strider 2015년 12월 9일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

John D'Errico
John D'Errico 2015년 12월 9일
편집: John D'Errico 2015년 12월 9일
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 2015년 12월 9일
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
David K
David K 2015년 12월 9일
I would say that as a numeric system that is base 10, the default base for log() should also be base 10. But that's more of an opinion than a standard.
And I know I can create an alias for ln() which leads to log(), but the bigger issue is the misuse of log() as log10(). I don't really expect a workaround or a change to Matlab, since that would break all legacy code. I'm just hoping for an understanding of this design choice.
Walter Roberson
Walter Roberson 2015년 12월 9일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by