Definite Integral Calculator

Numerically evaluate definite integrals of common and custom functions with composite Simpson's rule, and plot the curve, shaded area, and integration bounds.

FreeOnline Tool
Loading…

How to Use

The default is ∫sin(x)dx over [0, π]; changing the function, interval, or step count recalculates and redraws automatically.

  1. Choose a preset function from the f(x) selector: sin, cos, tan, ln, log₁₀, e^x, √x, |x|, xⁿ, x, x², x³, or Custom Expression.
  2. Set coefficient A and offset B so the integrand is y = A·f(x) + B. For the power function, also set the exponent n.
  3. Enter the lower bound, upper bound, and number of steps. Steps are clamped to 100–10000 and rounded to an even number; bounds must be finite and the lower bound must be less than the upper bound.
  4. For a custom expression, enter a formula in x such as 2*sin(x)+1 or x^2-3*x+2. Implicit multiplication, parentheses, ^, and common math functions are supported.
  5. The result shows the integral to six decimals plus the expression and interval. The canvas draws the curve, a blue shaded integral area, and red/green dashed lines at the bounds.
  6. Use the quick chips (sin 0→π, x² 0→1, e^x 0→1, ln 1→e) to switch examples. “Load sample” fills 2sin(x)+1, “Reset” restores the defaults, “Copy result” copies the text, and “Download PNG” saves the plot.

Features

  • Composite Simpson's rule: evaluates (h/3)×[f₀ + 4f₁ + 2f₂ + … + fₙ], with more steps giving a finer approximation. Steps are clamped to 100–10000 and made even.
  • Many function types: 12 presets plus custom expressions. Presets support coefficient A and offset B, and the power function takes an exponent n.
  • Safe expression parser: custom expressions are compiled by a built-in parser without eval or new Function. Supports + - * / % ^, parentheses, implicit multiplication (2x, 2sin(x)), functions sin cos tan asin acos atan sinh cosh tanh ln log log10 log2 sqrt cbrt abs exp pow min max hypot floor ceil round trunc sign, and constants pi, π, e.
  • Domain handling: ln, log₁₀, √x, and similar functions return invalid points outside their domain. A few invalid points are treated as zero; if more than 10% of samples are invalid, the tool reports an error instead of a misleading value.
  • Visualization: Canvas rendering of the curve, shaded area, bound markers, and axes. The y-range discards extreme values such as tan asymptotes so the plot stays readable.
  • Export: copy the integral result or download the plot as a PNG. All computation happens locally in the browser.

Use Cases

Check calculus homework
Evaluate definite integrals of sin, x², e^x, ln, and similar functions and compare them with the analytical answer.
Estimate area under measured curves
Write a fitted or measured function as a custom expression and estimate the area over a given interval, such as a power or flow curve.
Numerical integration in probability
Integrate a custom density function that has no simple antiderivative to estimate interval probabilities or normalizing constants.
Teach integrals as area
Use the curve, shaded integral region, and bound markers to show the relationship between a definite integral and the area under a curve.

FAQ

Which functions and expression syntax are supported?
Presets: sin, cos, tan, ln, log₁₀, e^x, √x, |x|, xⁿ, x, x², x³. Custom expressions support +, -, *, /, %, ^, parentheses, and implicit multiplication. Functions include sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, ln, log (base 10), log10, log2, sqrt, cbrt, abs, exp, pow, min, max, hypot, floor, ceil, round, trunc, and sign. Constants are pi, π, and e.
What algorithm is used, and how accurate is it?
It uses composite Simpson's rule, a numerical method, not symbolic antiderivative evaluation. More steps usually improve accuracy, but the result remains an approximation. Steps are clamped to 100–10000 and made even, and the value is shown to six decimals.
Why does it report many invalid points?
When the function is undefined over much of the interval, such as ln(x) or √x over negative values or tan(x) crossing multiple asymptotes, the tool counts invalid samples. Above 10% of the step count it reports an error; a few invalid boundary points are treated as zero.
Can the bounds be reversed?
No. The lower bound must be less than the upper bound; equal or reversed bounds produce “the lower bound must be less than the upper bound.” To evaluate a reversed interval, swap the bounds and negate the result yourself, or adjust the integrand.
Is the custom expression safe, and is data uploaded?
Expressions are compiled and evaluated by a built-in tokenizer/parser without eval or new Function. Sampling, integration, and drawing all happen in the browser, and no expression or data is sent to a server.
Why does the curve break in some places?
The plot breaks the line at points that are undefined, non-finite, or far outside the current y-range, such as tan asymptotes, to avoid drawing a false vertical line. The integral calculation applies its own invalid-point rule separately.