Discussion
Started 19th Jun, 2020

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?

Most recent answer

16th Jul, 2020
Kareem Taha Elgindy
King Fahd University of Petroleum and Minerals
Dear brother and one of my best friends Mahmoud,
"you are really great researcher" This is how I see you.
Warmest regards,
Kareem

All replies (9)

21st Jun, 2020
Baraa Mohandes
Khalifa University
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.
21st Jun, 2020
Kareem Taha Elgindy
King Fahd University of Petroleum and Minerals
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
21st Jun, 2020
Muhammad Ali
Charles Sturt University
Because, It is not a rational number.
21st Jun, 2020
Kareem Taha Elgindy
King Fahd University of Petroleum and Minerals
Dear Muhammad,
pi is also irrational, but it's defined in MATLAB.
Regards,
Dr. Kareem
21st Jun, 2020
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
21st Jun, 2020
Colin Sokol Kuka
The University of York
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.
23rd Jun, 2020
Kareem Taha Elgindy
King Fahd University of Petroleum and Minerals
@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.
15th Jul, 2020
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.
Can you contribute to the discussion?

Similar questions and discussions

Related Publications

Article
Thesis (M.A.)--Wake Forest College, Department of Mathematics, 1963. Bibliography: p. 18.
Article
Full-text available
One of the most important constants of mathematics is the Euler's number. Many world mathematicians have studied the properties of number and this number has an irreplaceable place not only in mathematics but also in other scientific disciplines. In the first part of the article we will focus on the introduction of the number from a historical view...
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...
Got a technical question?
Get high-quality answers from experts.