How to write log base e in MATLAB?
Show older comments
.png)
I have attached a picture of what i am trying to type in MATLAB. I get an error when i put loge(14-y), so im assuming im typing it wrong and MATLAB cannot understand what i am looking for. Any help would be great, Thank you
4 Comments
Dimitris Kalogiros
on 1 Oct 2019
You don't have to define the base. Just write log(14-y).
In matlab , log(x) means ln(x).
jinhu
on 28 May 2023
In matlab, the general log (without radix) is equivalent to natural logarithm (e). Generally, the legal radix in matlab is only 2 and 10
John D'Errico
on 28 May 2023
Edited: John D'Errico
on 28 May 2023
@jinhu - I'm sorry, but that is a meaningless statement. There is no "legal" radix. If you are thinking 2 is a valid radix, since numbers are stored in binary form, you would be vaguely correct. But 10 would simply not apply, since MATLAB only uses a base of 10 to display the numbers. Nothing is stored as a decimal. Anyway, any log computation has essentially nothing at all to do with the way the numbers are stored internally anyway.
If you are talking about syntactic legality, there are THREE syntactically legal log bases: 2, 10, and e, since we have the functions log2, log10, and log in MATLAB. And, if I had to make a bet, I would seriously bet that the log2 and log10 functions merely encode the simple:
log(x,b) = log(x)/log(b)
They might special case certain values of x, so when x==10, you want log10(10) to be exactly 1.
log10(10) == 1
Walter Roberson
on 26 Feb 2025
Weirdly, it appears that on the X64 architecture, the instruction is FYL2X which is Y*log2(X) , with the logic

So you would pre-load the "Y" with 1/(log 2 of the base) and then the instruction would calculate log 2 of the value and multiply it by Y.
There is a related instruction y ∗ log2 (x +1)
But other than that... there does not appear to be any log base e instruction.
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!