Two-Point Gauss-Legendre Quadrature Calculator
This two-point Gauss-Legendre quadrature calculator approximates the definite integral of a polynomial over a finite interval.
Run — free
Enter coefficients in descending powers, then provide the lower and upper bounds. The calculator maps the standard nodes from [-1, 1] onto your interval, evaluates the polynomial twice, and combines those values with the correct scale factor. It also reports the exact polynomial integral and absolute error, making the result useful for learning, checking hand calculations, and testing numerical integration code.
Enter the polynomial and interval clearly
Represent the polynomial with coefficients arranged from the highest power down to the constant term. For example, the array [2, -3, 0, 5] means 2x³ - 3x² + 0x + 5. Keep explicit zeros when an intermediate power is absent, because the position of every coefficient determines its exponent. Then enter a finite lower bound and a finite upper bound, with the upper bound strictly greater than the lower bound. The calculator accepts constant and higher-degree polynomials, up to the documented coefficient limit. It does not parse a symbolic expression such as “x squared plus one”; the numeric coefficient array removes ambiguity about precedence, signs, and missing terms. Before calculating, check that the interval direction matches the definite integral you intend. If you need the integral in the reverse direction, swap the endpoints yourself and negate the reported result. This deliberate requirement makes the displayed mapping and positive interval scale straightforward to inspect.
Understand the mapping and weighted evaluation
Two-point Gauss-Legendre quadrature begins with two standard nodes, -1/√3 and 1/√3, each having weight one on the standard interval [-1, 1]. For an interval [a, b], the calculator uses its midpoint (a + b)/2 and half-width (b - a)/2. Each standard node t is mapped to x = midpoint + half-width × t. The polynomial is evaluated only at those two mapped x values. Their sum is then multiplied by the half-width, producing the quadrature approximation. The output exposes both the standard and mapped nodes, along with each function value, so every part of the calculation can be reproduced independently. Gauss-Legendre nodes are chosen to achieve more algebraic accuracy than equally spaced sample points with the same number of evaluations. There are no endpoint evaluations in this rule, and no adaptive subdivision; the result is one application of the classical two-node formula across the entire requested interval.
Interpret exactness and the reported error
A Gauss-Legendre rule with two nodes integrates every polynomial of degree three or less exactly in exact arithmetic. For quartic and higher-degree polynomials, it generally gives an approximation, although special coefficients or symmetric intervals can occasionally cancel the error. The exact_for_polynomial field therefore describes the general degree guarantee, not a claim based only on a displayed zero error. Because the input is already a polynomial, the calculator also obtains an exact reference value by integrating every monomial analytically and evaluating the resulting antiderivative at both bounds. The absolute_error field is the nonnegative difference between that reference and the quadrature approximation. Small residuals can appear for theoretically exact cases because JavaScript numbers use finite-precision floating-point arithmetic. Use the comparison to study how polynomial degree, interval width, and symmetry affect a fixed quadrature rule. For difficult high-degree or large-coefficient inputs, rescaling the variable can reduce overflow and rounding sensitivity before applying numerical integration.
What you can do with it
Check a numerical analysis exercise
Compare mapped nodes, sampled values, and the final approximation with each line of a hand calculation.
Demonstrate cubic exactness
Try polynomials through degree three on different intervals and inspect the exact reference and floating-point error.
Build regression fixtures
Generate deterministic quadrature results for tests of polynomial evaluation, interval mapping, or integration software.
FAQ
What does a coefficient array mean?
Coefficients are listed in descending powers. [3, 0, -2] represents 3x² - 2, with the zero preserving the missing linear term.
Why are the standard nodes plus and minus 1 divided by square root of 3?
Those are the roots of the second Legendre polynomial. With equal weights, they make the rule exact for every polynomial through degree three.
Does the method evaluate the interval endpoints?
No. Both mapped nodes lie inside the interval; the two-point Gauss-Legendre rule does not sample either endpoint.
Why can an exact cubic show a tiny error?
The mathematical rule is exact for cubics, but nodes and arithmetic are represented with finite-precision floating-point numbers, so a small rounding residual may remain.
What does it cost?
Each API request costs $0.002. The browser version runs locally without a network calculation.
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/calculus/gauss-legendre-2point \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"coefficients":[1,0,0],"lower_bound":0,"upper_bound":1}'const res = await fetch("https://api.kit.forhosting.com/calculus/gauss-legendre-2point", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"coefficients": [
1,
0,
0
],
"lower_bound": 0,
"upper_bound": 1
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/calculus/gauss-legendre-2point",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"coefficients": [
1,
0,
0
],
"lower_bound": 0,
"upper_bound": 1
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/calculus/gauss-legendre-2point", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"coefficients":[1,0,0],"lower_bound":0,"upper_bound":1}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"coefficients":[1,0,0],"lower_bound":0,"upper_bound":1}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/calculus/gauss-legendre-2point", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"coefficients": [
1,
0,
0
],
"lower_bound": 0,
"upper_bound": 1
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "calculus.gauss_legendre_2point",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |