Discussion
Started 19th Jun, 2020
  • Xiamen University Malaysia

Why Euler's number e = 2.71828... is not a built-in constant in MATLAB?

I understand that we can produce that number in MATLAB by evaluating exp(1), or possibly using exp(sym(1)) for the exact representation. But e is a very common constant in mathematics and it is as important as pi to some scholars, so after all these many versions of MATLAB, why haven't they recognize this valuable constant yet and show some appreciation by defining it as an individual constant rather than having to use the exp function for that?
Below is a conversation between me and MATLAB illustrating why MATLAB developers have ZERO common sense... Enjoy the conversation dear fellows and no regret for MATLAB staff...
Me: Hello MATLAB, how is things?
MATLAB: All good! How can I serve you today sir?
Me: Yes, please. Could you give me the value of Euler's number? You know... it's a very popular and fundamental constant in mathematics.
MATLAB: Sure, but wait until I call the exponential function and ask it to evaluate it for me...
Me: Why would you call the exponential function bro??? Isn't Euler's number always constant and its value is well known for thousands of digits?
MATLAB: You will never know sir... Maybe its value will change in the future, so we continuously check its value with the exponential function every time I'm turned on...
Me: You do WHAT!!!
MATLAB: Well... This is a normal procedure sir and I have to do this every time you turn me on...
Me: Stop right there and don't tell me more please...
MATLAB: No, wait sir... I agree with you that this is perhaps one of the most cloddish things that was ever made in the history of programming, but what can I do sir? The guys who developed me actually believe that this is ingenius.
Me: Ooooh oooh ooooh.... reeeeeally!!! Now ain't that something...
MATLAB: They say sir that this is for your security plus there are no applications for that number sir, so why should they care? Even Euler himself, if resurrected again, would fail to find a single application for that number sir. Probably Jacob Bernoulli, the first to discover this number in 1683, would fail also sir, so why should we bother sir? Though it's a mathematical constant and deeply appreciated by the mathematicians around the world for centuries, we don't respect that number sir and find it useless.
Me: Who decides on the importance of Euler's number as a mathematical quantity? Mathematicians or the guys who develop you?
MATLAB: The guys who develop me sir; right?!?!?!?!?
Me: Bro I was obsessed with you in the past and I was truly a big fan of you for more than a decade. But, with the mentality I saw here from the guys who develop you, I believe you will beset with fundamental issues for a long time to come bro... No wonder why Python have beaten you in many directions and became the most popular programming language in the world. Time to move to Python you closed minded and thanks for helping me in my research works in the past decade!!! Good bye for good.
MATLAB: Wait sir... Don't leave please... As a way to compensate for the absence of Euler's number, we offer the 2 symbols i and j sir to represent the complex unity, so the extra symbol is a good compensation for Euler's number...
Me: What did you just say?
MATLAB: Say what?
Me: You provide 2 symbols to represent the same mathematical complex unity quantity, but you have none for Euler's number???
MATLAB: Yeeeeeeeap... you got it.
Me: You can't be serious!
MATLAB: I swear sir by the name of the machine I'm installed in that this is true; I'm not making that up.
Me: But why 2 symbols for the same constant; pick up one for God sake!
MATLAB: Well... There is a wisdom sir for picking 2 symbols for the same constant not just 1.
Me: What is it?
MATLAB: Have you seen the movie "The Man in the Iron Mask" written by Alexandre Dumas and Randall Wallace or read the novel "The Three Musketeers," by the nineteenth century French author Alexandre Dumas sir?
Me: I only saw the movie. But why???
MATLAB: Then you must have heard the motto the movie heros lived by in their glorious youth, "One for all, all for one".
Me: Yes, I did...
MATLAB: We sir were very impressed by this motto, so we came up with a new one.
Me: Impress me!
MATLAB: "i for j, j for i".
Me: You're killing me...
MATLAB: Wait sir, there is more...
Me: More what?????
MATLAB: Many experts around the world project that the number of letters to represent the complex unity in MATLAB may reach 52 letters sir by the end of 2050, so that you can use any English letter (capital or small) to represent the complex unity. How about this sir? Ain't this ingenious also? Sir ?!!?!?!?!?
Me: And this is when common sense was blown up by a nuclear weapon... This circus is over...

Most recent answer

Kareem Elgindy
Xiamen University Malaysia
It's interesting to note that Python Developers define Euler's number as a built-in constant by invoking the supporting module math. In particular, math.e gives 2.718281828459045 without the silly computation of the exponential function at 1 as in MATLAB.
Thumbs up Python Developers 👍

All replies (11)

Baraa Mohandes
Luxembourg Institute of Science and Technology (LIST)
This is a coding language, not an award ceremony.
you can get euler's number with exp(1);
on the other hand, the number 'pi' can not be calculated directly from an operator like pi(1).
the imaginary number (i) can be written as sqrt(-1); but establishing distinction in the programming language between real and imaginary numbers requires declaring (i).
there are other important numbers which aren't represented at all. i.e. Fibonacci's number. what could be more important than the divine constant?
anyway, create the following matlab scrcipt:
function out=e
out = exp(1);
end
and name the file e.m, and place it in your MATLAB path.
i hope this solves your problem.
Kareem Elgindy
Xiamen University Malaysia
Thanks Baraa. There are a few points that I would like to comment on your answer though:
1. If speed is of concern, then the sample code you gave is slower than executing exp(1) because it involves two calls. One for e and one for exp(1).
2. Calling the file you suggested after placing it in the MATLAB path is even slower, because MATLAB searches for built-in functions first. In this case calling exp is faster indeed.
3. e in MATLAB stands for 10, so using the code you gave will conflict with the scientific notation e.
4. exp(1) will evaluate the exponential function at x = 1. Why should we evaluate a function at a number x = 1 when we already know its value (Euler's number)? Can't MATLAB just define this constant as a built-in constant and use it without having to calculate exp at x=1?
5. There are other important constants like the golden ratio that is used in various applications. In MATLAB to use this constant one way is to calculate (1+sqrt(5))/2. Why should we calculate this expression when its value is known 1.618033988749895? Can't MATLAB just define the golden ratio by this number?
6. I understand that calculating exp(1) and (1+sqrt(5))/2 are important if more than 16 significant digits are needed, but most numerical calculations are performed on double-precision floating-point systems, so their values up to this range of digits is often practical.
I started this discussion a couple of days ago on a different server, but I wanted to hear from a wider audience about this subject. If interested, you may read an extension to this topic in https://www.mathworks.com/matlabcentral/answers/549723-why-euler-s-number-e-2-71828-is-not-a-built-in-constant-in-matlab#answer_454609?s_tid=prof_contriblnk .
Best wishes,
Dr. Kareem
Muhammad Ali
Charles Sturt University
Because, It is not a rational number.
Kareem Elgindy
Xiamen University Malaysia
Dear Muhammad,
pi is also irrational, but it's defined in MATLAB.
Regards,
Dr. Kareem
Anton Vrdoljak
University of Mostar
Maybe the reason is one that we are able to round any number to specified number of decimal digits. For example, if we want to round pi to the nearest 3 decimal digits, we will use this command: Y = round(pi, 3),
and it will result with: Y = 3.1420
Colin Sokol Kuka
The City of Liverpool College
Eulero number or other mathematical number are infinite. You should decide how many decimals you need. If you wait that MATLAB decide the precision of infinite long number you could wait for ages. Human life is limited.
Kareem Elgindy
Xiamen University Malaysia
@Anton: Thanks for sharing your comment with me. To round e using exp to say 3 digits we would type round(exp(1),3). Instead if e is defined in MATLAB by en, say, then we would type round(en,3). The former requires two function calls while the latter would require only one call. In terms of speed, the latter is reasonably faster.
@Colin: Good point. That’s why I suggest to define e as a constant instead. In most common floating-point systems, one typically use double-precision floating point representations; thus working with about 16 significant digits—with the last digit being a random junk digit in certain computations. So, defining e by this finite range of digits is very practical.
@Emad: Salam Alaikom my deer friend, colleague, and one of my favorite teachers who ever taught me. I feel so delighted that you shared your comment here in this forum. You have a point indeed that this would be a kind of redundancy. But it remains important to ask: why should we evaluate exp at x=1 when e is a very known value? In almost all algorithms I developed in my career so far, I frequently use constant parameter inputs defined as double-precision numbers, i.e. are represented by 16 significant digits. In double-precision floating-point systems, this is typically the case. So why should we ask MATLAB to compute exp at x=1 when we can use its 16 significant digits representation instead. This would be faster and computationally more efficient. How about other important constants like the golden ratio which does not occur redundant with other functions? Why should we calculate them when their values are very known values? One of the reasons MATLAB Developers are proud of is that they have a huge library of functions that can help programmers and users to do certain tasks with minimal programming efforts, but they fail to have even a decent library for important mathematical constants. If they define these constants, we could use them directly in our works without having to calculate them using other functions or formulas. To calculate an expression like sin(exp(1)*x)+3*exp(1), why should we ask MATLAB to calculate the exponential function twice at x=1, when we could easily define exp(1) as a constant, say en, and type sin(en*x)+3*en; this would be faster and computationally cost effective indeed. Of course, if one needs more accuracy than 15 or 16 significant digits, we can then ask MATLAB to evaluate the exp function at x=1. But I, as a computational mathematician, never used more than 16 significant digits in all my previous works except when I wanted to compare my approximations with the exact values of the solution—I typically prefer to use MATHEMATICA in this case. Once again I thank you for sharing your smart comment with us. Stay safe my dear teacher.
Mahmoud Owais
Assiut University
My dear Dr. Kareem
you are really great researcher
I don't realize that your point is worthy until i read your complete argument.
Great job, and I hope that they add it.
Kareem Elgindy
Xiamen University Malaysia
Dear brother and one of my best friends Mahmoud,
"you are really great researcher" This is how I see you.
Warmest regards,
Kareem
Kareem Elgindy
Xiamen University Malaysia
As a follow up to the above discussion, a MATLAB file that can give the numerical value of Euler's number accurate to 10,000 significant digits is now available via https://www.mathworks.com/matlabcentral/fileexchange/77046-euler-s-number. You can download the file and add it to MATLAB path. To call the function just type en in the Command Window. To show Euler's number for 2 <= d <=10,000 digits, type vpa(en,d).
Kareem Elgindy
Xiamen University Malaysia
It's interesting to note that Python Developers define Euler's number as a built-in constant by invoking the supporting module math. In particular, math.e gives 2.718281828459045 without the silly computation of the exponential function at 1 as in MATLAB.
Thumbs up Python Developers 👍

Similar questions and discussions

Related Publications

Article
Based on the Lobatto quadrature, we develop several new closed form approximations to the mathematical constant e. For validating effectiveness of our approximations, a comparison of our results to the existing approximations is also presented. Another objective of our work is to inspire students to formulate other better approximations by using th...
Article
In this thesis, we discuss the relation between the Euler number of a tight contact small Seifert space and the contact framing of Legendrian vertical circles in it, and apply this relation to classify up to isotopy tight contact structures on small Seifert spaces with e₀ [not equal to] 0, -1, -2. Thesis (Ph. D.)--Massachusetts Institute of Technol...
Article
Piontkowski calculated the Euler number of Jacobi factors of plane curve singularities with semigroups $\langle p, q\rangle$, $\langle 4, 2q, s\rangle$, $\langle 6,8,s\rangle$ and $\langle 6,10, s\rangle$. %His analysis was done by decomposing the Jacobi factors into affine cells. In this paper, we show that a Jacobi factor for any curve singularit...
Got a technical question?
Get high-quality answers from experts.