Skip to main content
v2026.11,858 entries · CC-BY 4.0

Exponential in MATLAB: exp(), the Constant e and expm

Write an exponential in MATLAB with exp(x), get e as exp(1), and use expm for matrix exponentials; worked syntax from MathWorks docs.

Written and maintained by CASRAI Editorial Board

Last updated

In MATLAB the exponential function is exp: Y = exp(X) returns ex for each element of X. There is no e^x operator and no built-in variable named e; the number e is exp(1), which displays as 2.7183. This guide is for researchers and analysts who need to write exponentials correctly, tell exp from the matrix exponential expm, and read the output.

What exp is used for in research

The exponential function appears wherever growth, decay or likelihood models do: exponential growth and decay curves, rate laws, survival and hazard models, softmax and log-likelihood calculations, and transformations that reverse a natural logarithm. In MATLAB, exp is the single function behind all of these, and it works on a whole array at once. To go the other way (from a value back to its exponent), see natural logarithm in MATLAB and ln in MATLAB; to fit an exponential model to data, see fit in MATLAB.

Install or access

exp is part of base MATLAB, so no toolbox is needed. Documentation for the function is published by MathWorks at mathworks.com/help/matlab/ref/double.exp.html. Licensing and access options are on the MathWorks website; this page does not cover pricing.

How do you write exponential in MATLAB?

Use exp(x). The documented syntax is Y = exp(X), which returns ex for each element of X. The input can be a scalar, vector, matrix, N-d array, table or timetable, of type single or double, and complex values are supported.

Exponential function in MATLAB: step by step

  1. Put your values in a variable: X = -2:0.5:10;
  2. Apply the function: Y = exp(X/2); This is the documentation’s own plotting example and computes ex/2 for every element.
  3. Plot it: plot(X,Y). For labels and axes, see MATLAB plot label and MATLAB graphing.

The scaling in step 2 answers “how to add” a coefficient to the exponent: divide or multiply the argument inside exp, as in exp(X/2). The exponent is whatever expression you pass in.

What is exponential e in MATLAB?

The constant e is obtained as exp(1). MATLAB’s documentation shows it returning 2.7183, which is the default short display of the stored double-precision value, not the full stored precision. Use exp(1) wherever a formula says e; for e2, write exp(2).

What is exp() in math?

exp(x) is the exponential function, e raised to the power x. For a complex number z = x + iy, MATLAB’s documentation gives ez = ex(cos y + i sin y). Setting x = 0 and y = π gives Euler’s identity result, which MATLAB shows for Y = exp(1i*pi) as -1.0000 + 0.0000i.

exp versus expm: element-wise or matrix exponential

For a matrix, exp and expm are different operations. MathWorks states: “Use expm to compute a matrix exponential,” and, on the expm page, “Use exp for the element-by-element exponential.” The expm input must be square.

Function What it computes Input Documented example, A = [1 1 0; 0 0 2; 0 0 -1]
exp(X) ex of each element separately Scalar, vector, matrix, N-d array, table, timetable First row of exp(A): 2.7183 2.7183 1.0000
expm(X) The matrix exponential Square matrix First row of expm(A): 2.7183 1.7183 1.0862

In that example the diagonals agree because the matrix is triangular, but the off-diagonal entries differ. MathWorks also notes that expm(X) equals V*diag(exp(diag(D)))/V when X has a full set of eigenvectors (from [V,D] = eig(X)), though expm is not computed that way. For eigenvalues, see eigenvalue in MATLAB.

Output and how to read it

  • The output Y has the same data type as X.
  • For real input, the result is positive.
  • For complex input, the result is complex.
  • Displayed digits (such as 2.7183) reflect the display format, not the stored value; use format long to see more digits, or see fprintf in MATLAB to control printed output.

Troubleshooting

  • Error or wrong result from e^x. MATLAB has no e^x operator for the constant; write exp(x).
  • Matrix result looks wrong. If you wanted the matrix exponential, exp(A) gives element-wise values; use expm(A).
  • expm errors on your input. expm requires a square matrix.
  • Unexpected complex output. Complex input gives complex output; check whether your data contain an imaginary part.

Free alternatives

Tool Element-wise exponential Matrix exponential
GNU Octave exp(x) expm(A)
Python (NumPy, SciPy) numpy.exp(x) scipy.linalg.expm(A)
Julia exp(x) (broadcast with exp.(x)) exp(A) on a square matrix

Note that Julia reverses MATLAB’s convention: exp on a square matrix is the matrix exponential, and the dot form is element-wise.

FAQ

How do you write exponential in MATLAB?

Write exp(x), for example exp(X/2) on a vector X.

What is exp() in math?

It is e raised to the power x, the inverse of the natural logarithm.

What is exponential e in MATLAB?

exp(1), displayed as 2.7183.

How to add exponential e?

Scale or shift the argument inside exp, such as exp(X/2); to include e in a formula, use exp(1) or fold it into the exponent.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Exponential in MATLAB: exp(), the Constant e and expm

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →