Why does Matlab use 'log' instead of 'ln'?
179 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
Image Analyst
2015 年 12 月 9 日
Probably because most other languages follow that same naming convention. Not sure why, just historical I guess.
3 件のコメント
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
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."
0 件のコメント
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 件のコメント
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!