How to use the constant e in MATLAB?

So the question is given x =0.2 calculate (x^2) *e^4. I know for pi you just type pi which is just pi in the command. But how do I type e in the command window. Also how to use exponents? Do you just go (x^2) ? Do I need those brackets?

9 Comments

If Star's answer met your needs, please formally Accept it.
Abdalla
Abdalla on 19 Sep 2022
Moved: Voss on 19 Sep 2022
x1 = 𝑒𝑗8𝜋/7
x1 = exp(1j*8*pi/7)
x1 = -0.9010 - 0.4339i
Jeeimy
Jeeimy on 22 Oct 2023
Moved: DGM on 22 Oct 2023
Y=e^(1.2*t)
Use exp(). It's the same answer that's already been demonstrated several times on this page.
when i am using this normal e the code does not work mos, what should i do?
Stephen23
Stephen23 on 18 Apr 2025
Edited: Stephen23 on 18 Apr 2025
"when i am using this normal e the code does not work mos, what should i do?"

Sign in to comment.

 Accepted Answer

Star Strider
Star Strider on 29 Oct 2026 at 0:00
Edited: MathWorks Support Team on 24 Sep 2026
Use the exponential function exp(y) to compute e^y. For example: 
x = 0.2;
Result = (x^2)*exp(4)
Result =
2.1839

3 Comments

Cai Walsh
Cai Walsh on 13 Mar 2022
Moved: John D'Errico on 29 Oct 2026 at 18:59
say i needed Vout = VS (1 − e^-T/RC) , how would i write this as ive tried exp(-T/R*C) but wouldt work as theres a negative
T = 2;
R = 5;
C = 7;
y = exp(-T/R*C)
y = 0.0608
z = exp(-14/5)
z = 0.0608
Or did you want to divide by the product of R and C?
w = exp(-T/(R*C))
w = 0.9445
q = exp(-2/35)
q = 0.9445
For more details, see exp documentation page: exp - Exponential - MATLAB

Sign in to comment.

More Answers (2)

Harsh
Harsh on 18 Oct 2021
e=exp
then use bracket
i.e. e^5=exp(5) in matlab
There are significant issues in this. Some (@Harsh, for example) have suggested creating a variable named e. And while this can work, it also has problems.
First, exp is vectorized. That is, if you define e as a variable, beware if the exponent is a vector or array. You WILL need to use the .^ operator. It will fail if you do not.
e = exp(1);
x = 1:5;
e.^x
ans = 1×5
2.7183 7.3891 20.0855 54.5982 148.4132
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
e^x
Error using ^ (line 29)
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To operate on each element of the matrix individually, use POWER (.^) for elementwise power.
Next, can you raise a negative value? That is, suppose you have the expression e^-x^2, where this is a gaussian like thing? So you need to compute -x^2, then raise e to that power.
>> x = 2;
>> e^-x^2
ans =
0.018316
>> e^(-x^2)
ans =
0.018316
As you can see, both yield the same result due to the order of operations in MATLAB as long as you use the vectorized operator when vectrs or arrays are involved, but using parens is FAR FAR safer, if you have even the slightest uncertainty about how such an expression will be evaluated.
The biggest issue is with time. exp is considerably faster to evaluate, if the arrays are at all large.
>> x = randn(1,1e8);
>> timeit(@() e.^x)
ans =
0.22558
>> timeit(@() exp(x))
ans =
0.056586
The difference is essentially 4 to 1 faster for exp.

Categories

Products

Tags

Asked:

on 14 Sep 2016

Answered:

on 29 Oct 2026 at 19:25

Community Treasure Hunt

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

Start Hunting!