Written and maintained by CASRAI Editorial Board
Published
On this page
MATLAB’s quad function (also searched as “quad matlab”) computes a definite integral of a function between two finite limits. The current MathWorks reference page states plainly that “quad is not recommended. Use integral instead.” This guide shows the exact quad syntax so you can read or reproduce older analysis code, then converts a quad call to integral side by side, including what changes in tolerances and limits.
What quad is used for in research
You will meet quad mostly in inherited scripts: a lab’s older analysis code, supplementary code from a published paper, or a thesis chapter that integrates a model curve, a probability density or a rate over a finite interval. The quad version history lists it as introduced before R2006a, and the documentation page carries no removal notice. If you are writing new code, the same page points you to the integral function; see also numerical and symbolic integration in MATLAB.
Install or access
quad is documented in the core MATLAB function reference (the matlab/ref section of MathWorks help), so no add-on toolbox page is listed for it. Get MATLAB and its documentation from MathWorks (mathworks.com); the function reference is at mathworks.com/help/matlab/ref/quad.html. Check your institution’s MATLAB licence terms with your IT or library service. Without a licence, see the free alternatives table below.
Step-by-step: integrate a function with quad
Documented syntaxes are q = quad(fun,a,b), q = quad(fun,a,b,tol), q = quad(fun,a,b,tol,trace) and [q,fcnEvals] = quad(___).
- Write the integrand as a function handle.
funmust accept a vectorxand return a vectoryof the same size, so use array operators (.^,.*,./), not matrix operators. Anonymous functions work well; see lambda (anonymous) functions in MATLAB. - Set finite limits.
aandbare separate finite scalars (single or double). - Optionally set the tolerance.
tolis a scalar absolute error tolerance applied to each subinterval; the default, used when you pass[]or omit it, is 1e-6. - Call quad.
f = @(x) exp(-x.^2);
q = quad(f, 0, 2)
For this integrand the exact value is (√π/2)·erf(2) ≈ 0.88208139 (computed analytically, not as MATLAB output), a quick check that you typed the integrand correctly.
Output and how to read it
qis a scalar: the estimated integral.fcnEvals(second output) is a scalar count of function evaluations.- If
traceis nonzero,quaddisplays[fcnEvals, a, b-a, Q]for each subinterval as it works, which shows where the routine concentrated its effort.
The documented outputs contain no separate error estimate, so judge accuracy by tightening tol and checking that q stops changing.
Moving from quad to integral
This is where most inherited code needs attention. The integral reference documents q = integral(fun,xmin,xmax) and q = integral(fun,xmin,xmax,Name=Value). The table compares the two reference pages.
| Item | quad | integral |
|---|---|---|
| Status in the docs | “Not recommended. Use integral instead.” | The function the quad page recommends |
| Basic call | quad(fun,a,b) |
integral(fun,xmin,xmax) |
| Limits | Separate finite scalars | Same call form |
| Absolute tolerance | Positional tol, default 1e-6, per subinterval |
AbsoluteTolerance, default 1e-10 (named AbsTol before R2026b; old name still works) |
| Relative tolerance | None documented | RelativeTolerance, default 1e-6 (named RelTol before R2026b; old name still works) |
| Array-valued integrand | Vector in, vector out | Same by default; ArrayValued=true when fun takes a scalar and returns a fixed-size array |
| Hard spots in the interval | No option documented | Waypoints option for mesh points near extrema or discontinuities |
| Evaluation count / trace | fcnEvals output and trace argument |
No equivalent in the documented syntax |
Worked rewrite of the earlier call, with the tolerance made explicit:
f = @(x) exp(-x.^2);
% legacy
q_old = quad(f, 0, 2, 1e-6);
% current
q_new = integral(f, 0, 2, AbsoluteTolerance=1e-6);
Passing the old tol value as AbsoluteTolerance mirrors the old setting, but the two functions have different tolerance rules, so treat results as agreeing within the tolerance you set rather than digit for digit. The quad reference only states “use integral instead”; it does not give a one-to-one mapping beyond that. If your old script depended on fcnEvals or trace, log evaluations another way, for example a counter inside your own function.
Other functions named on the quad page as related are quadgk, integral2, integral3, quad2d and trapz.
Troubleshooting
- Dimension errors such as “matrix dimensions must agree”: the integrand uses
*,^or/instead of.*,.^,./.quadpasses a vector tofun. - Infinite limits:
quaddocuments finite scalar limits only. - Singularities inside the interval (integral): the documentation says not to use
Waypointsto specify singularities; split the interval at the singular point and add the pieces.Waypointsis for extrema and discontinuities. - Result changes when you migrate: compare tolerances first (table above); the default absolute tolerances differ by four orders of magnitude (1e-6 versus 1e-10).
- Parameters in the integrand: capture them in the anonymous function (
f = @(x) a*x.^2).
Free alternatives
| Tool | Function | Documented behaviour |
|---|---|---|
| GNU Octave | quad(f,a,b[,tol[,sing]]) |
Uses QUADPACK routines; default absolute and relative tolerance about 1.5e-8 (sqrt(eps)); either or both limits may be infinite; returns q, ier, nfev, err. |
| GNU Octave | integral(f,a,b[,prop,val,...]) |
AbsTol 1e-10, RelTol 1e-6 by default (double precision); infinite limits allowed; returns q and an absolute error estimate. |
| Python (SciPy) | scipy.integrate.quad(func,a,b,...) |
Wraps QUADPACK; epsabs and epsrel default to 1.49e-8; infinite limits via numpy.inf; returns the integral and an absolute error estimate. |
Octave’s quad shares a name with MATLAB’s but is a separate implementation with different defaults and an error-flag output, so check tolerances and outputs before porting code.
FAQ
What does quad do in MATLAB?
It numerically integrates a function handle between two finite limits and returns the integral estimate, optionally with a count of function evaluations. MathWorks marks it “not recommended” in favour of integral.
Has quad been removed from MATLAB?
The R2026b reference page for quad (read 2026-11-07) shows no removal notice, only the not-recommended note.
What replaces quad?
MathWorks says to use integral. The related functions integral2 and integral3 are listed on the same page.
Is “quad matlab” a different function from quadgk?
No, “quad matlab” just means the quad function. quadgk is a separate function listed as related; the pages read do not map one to the other, so consult its own reference before swapping.
Related CASRAI guides: Integrating MATLAB, linspace in MATLAB and the MATLAB equation solver.
Sources
- MathWorks, quad (R2026b documentation), https://www.mathworks.com/help/matlab/ref/quad.html, read 2026-11-07.
- MathWorks, integral, https://www.mathworks.com/help/matlab/ref/integral.html, read 2026-11-07.
- GNU Octave manual, Functions of One Variable, https://docs.octave.org/latest/Functions-of-One-Variable.html, read 2026-11-07.
- SciPy, scipy.integrate.quad, https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.quad.html, read 2026-11-07.







