Piecewise Integral Calculator Online Free
Piecewise Integral Calculator (Numeric)
Integrate a piecewise function numerically, piece by piece, and add the pieces — free, in your browser, nothing uploaded. Each piece is integrated with Simpson’s rule, so this is a numeric approximation, not a symbolic antiderivative.
from to
from to
from to
Use x, numbers, + – * / ^, brackets, and sin, cos, tan, exp, log, ln, sqrt, abs, pi, e.
Many real quantities are not described by a single neat formula. A tax rate changes at income thresholds. A delivery charge is one price up to a weight and another price beyond it. A force is one expression while a spring is compressed and a different expression afterwards. A signal is switched on, then off, then on again. In each case, the function is defined in pieces, with a different rule on each interval, and the question is often the total: the total tax, the total work, the total area under the curve, the total distance travelled. A piecewise integral calculator adds up the integrals of the pieces, one interval at a time, and gives you the total, with each piece's contribution shown separately so you can see where the total comes from.
Integration is, at heart, a way of adding up infinitely many tiny contributions, and for a piecewise function that addition naturally splits at the joins. If a function is x on the interval from 0 to 1 and x squared on the interval from 1 to 2, its integral over 0 to 2 is the integral of x over 0 to 1 plus the integral of x squared over 1 to 2, and no single antiderivative is needed to see that. The calculator at the top of this page performs that split numerically, using Simpson's rule on each piece, so it works for pieces you can type in even when finding antiderivatives by hand would be slow or impractical. This article explains what a piecewise integral means, how Simpson's rule approximates it, and where the numeric approach is reliable and where it is not, so the total it reports is something you can trust and check.
What It Is
An integral measures the signed area between a function's graph and the horizontal axis over an interval. When the function is positive, that area is above the axis and counts positively; when the function is negative, the area is below the axis and counts negatively, so the integral is a net area, not a total of absolute areas. A piecewise function is a function defined by different expressions on different intervals, often written with a brace and a list of cases, for example f(x) = x for 0 ≤ x ≤ 1 and f(x) = x² for 1 ≤ x ≤ 2. The integral of such a function over the whole range is the sum of the integrals over the pieces, because area, like any addition, can be split at any point and added back together. That splitting property is the entire mathematical idea behind this calculator, and it is what makes piecewise integration both conceptually simple and practically useful: you never need a single formula that covers everything, only a correct formula for each piece and the correct interval for each.
Simpson's rule, the numerical method this calculator uses, approximates an integral by fitting parabolas through triples of points instead of joining points with straight lines. Over each small subinterval, the function is approximated by a parabola through its values at the two ends and the midpoint, and the area under that parabola is computed exactly. Adding those parabolic areas over many small subintervals, one thousand per piece in this tool, gives an approximation that is remarkably accurate for smooth pieces: for a function that is itself a parabola or simpler, Simpson's rule is exact, and for other smooth functions the error shrinks very rapidly as the subintervals get smaller. The calculator states its method in its output note, so the approximation is disclosed rather than hidden, and for the live test below it reproduces the exact answer to four decimal places.
The tool accepts up to three pieces. Each piece needs an expression in x, a lower limit, and an upper limit, with the lower limit smaller than the upper limit. The third piece is optional, so a two-piece function like the live test uses only the first two rows. The pieces do not have to join up neatly in the tool, though in a genuine piecewise function they normally do: the end of one interval is the start of the next, and the expressions may or may not agree at the join. A jump at a join is allowed mathematically, and the integral is unaffected by what happens at a single point, but a piece that is undefined inside its interval, for example a division by zero or a logarithm of a negative number in the middle of the interval, will cause the tool to report an error rather than invent a number, which is the honest behaviour.
How to Use the Calculator
Using the tool takes less than a minute. Follow these steps:
- Enter the first piece's expression in x, for example x, and its lower and upper limits, for example 0 and 1.
- Enter the second piece's expression, for example x^2, and its limits, for example 1 and 2.
- If your function has a third piece, enter it in the third row; otherwise leave the third row blank.
- Use x, numbers, the operators + − * / ^, brackets, and the functions sin, cos, tan, exp, log, ln, sqrt, and abs, plus the constants pi and e, in any piece.
- Press "Calculate Total Integral". The tool shows the total integral and, separately, the integral of each piece, so you can check that the pieces add up to the total.
A few typing habits will save you errors. Write multiplication explicitly: 2*x, not 2x, because the tool reads a run of letters as a single symbol. Use brackets to make the order of operations clear, especially around powers and fractions: write (x + 1)^2 rather than x + 1^2 when you mean the square of the sum. Check that each piece's lower limit is smaller than its upper limit; a reversed interval is rejected with a clear message rather than silently giving a negative of the intended answer. And check that the intervals cover the range you intend without gaps or overlaps, unless a gap or overlap is deliberate, because the tool adds exactly the pieces you enter, no more and no less.
Worked Examples
Example 1: x on [0, 1] and x² on [1, 2], the live test
This is the test used to check the tool, and it is worth doing by hand as well as by calculator. The first piece, f(x) = x from 0 to 1, has integral x²/2 evaluated from 0 to 1, which is 1/2 − 0 = 0.5. The second piece, f(x) = x² from 1 to 2, has integral x³/3 evaluated from 1 to 2, which is 8/3 − 1/3 = 7/3, about 2.3333. Adding them gives 0.5 + 2.3333 = 2.8333. The calculator returns exactly that: piece 1 gives 0.5000, piece 2 gives 2.3333, and the total is 2.8333. The agreement to four decimal places is expected, because Simpson's rule is exact for the first piece, which is a straight line, and extremely accurate for the second piece, which is a parabola, over one thousand subintervals. This example also shows why the per-piece breakdown matters: if the total looked wrong, you could immediately see which piece was responsible, rather than having to guess.
Example 2: A constant, then a line, modelling a two-rate charge
Suppose a quantity accumulates at a constant rate of 5 units per unit of x from 0 to 3, and then at a rate of 2x from 3 to 5. The first piece is f(x) = 5, whose integral from 0 to 3 is 5 × 3 = 15. The second piece is f(x) = 2x, whose integral from 3 to 5 is x² evaluated from 3 to 5, which is 25 − 9 = 16. The total is 31. The calculator returns 15.0000, 16.0000, and 31.0000. This is the shape of many real problems: a flat rate, then a rising rate, and a total that is the sum of a rectangle and a curved area. It is also a good illustration of why piecewise thinking is unavoidable in applied work: no single simple formula describes a rate that changes its character halfway through, but two simple formulas, each on its own interval, describe it completely.
Example 3: A jump at the join
Consider f(x) = 1 from 0 to 1 and f(x) = 10 from 1 to 2. At x = 1 the function jumps from 1 to 10, and a student might worry that the jump breaks the integral. It does not. The integral is 1 × 1 + 10 × 1 = 11, and the calculator returns 11.0000. The reason is that an integral measures area, and a single point has no width, so the value at the jump point itself contributes nothing to the area, whichever piece you assign it to. This is a useful fact to remember, because real piecewise definitions often disagree about the join point itself, writing one piece as x ≤ 1 and the next as x > 1, or the reverse, and that choice does not affect the integral. What does affect the integral is the behaviour over intervals of positive length, and that is what the tool measures.
Example 4: A negative piece, and signed area
Take f(x) = x − 1 from 0 to 2. As a single piece, its integral is x²/2 − x evaluated from 0 to 2, which is (2 − 2) − 0 = 0. The calculator, given this as one piece from 0 to 2, returns 0.0000, and that is correct as a net area: the region below the axis from 0 to 1, where x − 1 is negative, has area 0.5, and the region above the axis from 1 to 2 has area 0.5, and they cancel. If you wanted the total absolute area, you would split the function at x = 1 into two pieces, x − 1 on [0, 1] and x − 1 on [1, 2], and add the absolute values of the two integrals, giving 1. The tool reports signed integrals, as is standard, so a total of zero does not mean nothing happened; it means the positive and negative contributions balanced. This example is included because it is the commonest misreading of an integral result, and naming it in advance prevents it.
Where Piecewise Integrals Appear
Piecewise integrals appear wherever a rate or a density changes its rule at a threshold, which is to say, in a large fraction of applied mathematics. In physics, work is the integral of force over distance, and a force that is one expression while a spring is in contact and another expression afterwards gives a piecewise work calculation. In economics, total cost is the integral of marginal cost, and marginal cost often changes at production thresholds. In probability, the total probability is the integral of a density function, and densities are frequently defined in pieces, for example a uniform density on one interval and an exponential density on another. In engineering, the deflection of a beam under a load that changes along its length is found by integrating a piecewise bending moment. In each case, the mathematical move is the same: split at the thresholds, integrate each piece, add. A tool that performs that move numerically, without requiring antiderivatives, removes the main practical barrier to doing these calculations, which is the algebra of finding and evaluating antiderivatives for each piece.
Tax is perhaps the most familiar piecewise example, and it is worth spelling out because it corrects a widespread misunderstanding. Income tax bands work by applying different rates to different slices of income, which is exactly a piecewise function: the first slice is taxed at one rate, the next slice at a higher rate, and so on. The total tax is the integral, or in the discrete case the sum, over the slices. The common error is to apply the highest rate to the whole income, which overstates the tax dramatically. A piecewise integral calculator, applied to a tax-rate function, gives the correct total, because it integrates each slice at its own rate. The same structure appears in postage, in utility tariffs, in data pricing, and in any system with tiers or thresholds, which is why piecewise thinking is a general life skill as much as a mathematical technique.
Simpson's Rule, Accuracy, and Its Limits
Simpson's rule earns its place in this tool because it is accurate for smooth functions with relatively few evaluations, and because its error behaviour is well understood. For a piece that is a polynomial of degree three or less, Simpson's rule is exact, up to floating-point rounding, no matter how wide the interval. For other smooth pieces, the error shrinks roughly as the fourth power of the subinterval width, which means that doubling the number of subintervals reduces the error roughly sixteenfold. With one thousand subintervals per piece, the error for ordinary smooth functions is far below the four decimal places the tool displays, which is why the live test matches the exact answer. That accuracy is not a guarantee for every function, however. A piece with a sharp spike inside its interval, a vertical asymptote, or a discontinuity inside the interval rather than at a join, will be approximated poorly, because Simpson's rule assumes the function is reasonably smooth between its sample points. The tool's honest response to a non-finite value is to report an error, but a function that is finite yet wildly varying can still give a misleading answer, and the best check is to split the piece at the troublesome point and integrate the two halves separately, or to compare with a hand calculation when one is available.
Limits: What This Tool Does and Does Not Do
This tool integrates up to three pieces numerically, using Simpson's rule with one thousand subintervals per piece. It does not find symbolic antiderivatives, so it will not return a formula for the integral, only a number, and it does not handle improper integrals over infinite intervals or intervals containing singularities, except by reporting an error when a value is not finite. It reports signed integrals, so a total of zero can mean cancellation rather than emptiness, as the example above shows. It does not check that your pieces join up, cover a range without gaps, or agree at the joins; it integrates exactly the pieces you enter, and the responsibility for entering the right pieces is yours. It displays four decimal places, which is a display choice, not a guarantee of four correct decimals for every function; for smooth pieces it is comfortably accurate, for spiky or singular pieces it is approximate, and the article has tried to make that distinction clear. Within those limits, the per-piece breakdown lets you verify every total by hand or by a second method, piece by piece.
Privacy: Your Numbers Stay in Your Browser
Every number and function you enter into this piecewise integral calculator stays in your browser. Nothing is uploaded to a server, nothing is stored, and there is no account to create. The calculation runs entirely on your own device. That matters even for a mathematics tool, because the functions people enter can be part of coursework, an exam revision session, or a piece of unpublished work, and that work deserves to stay private. Closing the page removes your inputs, and no one else sees them. This browser-only design is the same principle behind the other free tools on Your Smart Kit: a simple tool that does one job well, keeps your data private, and gives an answer you can check.
Frequently Asked Questions
What is a piecewise function?
It is a function defined by different expressions on different intervals, for example x on [0, 1] and x² on [1, 2]. The function as a whole has no single formula, but each piece does, and the integral over the whole range is the sum of the integrals over the pieces.
Why split the integral at the joins?
Because area adds up over intervals. The integral from 0 to 2 of a function that changes at 1 is the integral from 0 to 1 plus the integral from 1 to 2, regardless of what the function does at the single point 1. Splitting is what makes piecewise integration possible at all.
What is Simpson's rule?
It is a numerical integration method that approximates a function by parabolas through triples of sample points and adds the areas under those parabolas. It is exact for polynomials up to degree three and very accurate for smooth functions with many subintervals, which is why this tool uses one thousand subintervals per piece.
Does a jump at a join break the integral?
No. A single point has no width, so it contributes no area, and the integral is unaffected by which piece you assign the join point to. What matters is the behaviour over intervals of positive length on either side of the join.
Can the integral be zero even when the function is not zero?
Yes, when positive and negative areas cancel, as with x − 1 from 0 to 2, whose net integral is 0 even though the function is non-zero almost everywhere. If you need total absolute area, split at the zeros and add the absolute values of the pieces.
How many pieces can I enter?
Up to three, with the third optional. If your function has more than three pieces, integrate it in groups of three and add the group totals, or split it at its joins and use the tool repeatedly.
Related Tools on Your Smart Kit
If you found the piecewise integral calculator useful, you may also like the other free calculators on Your Smart Kit, including the partial differentiation calculator for rates of change in two variables, the infinite series calculator for adding terms one by one, and the geometry calculator for working with shapes and angles. Each runs in your browser, free, with no sign-up, and each is built on the same principle: a simple tool that does one job well, keeps your data private, and gives an answer you can check. Try the piecewise integral calculator at the top of this page with your own function, and see how a total that looks complicated becomes simple once it is split at its joins.
