Calculator overview
Inputs and outputs
This summary comes from the calculator's published input and output contract.
Inputs
- Point 2 y (required)
-
Default 0.8 Range -100 to 100
About this input
The y of point 2, from -100 to 100.
- Point 3 y (required)
-
Default 0.9 Range -100 to 100
About this input
The y of point 3, from -100 to 100.
- Point 4 y (required)
-
Default 0.1 Range -100 to 100
About this input
The y of point 4, from -100 to 100.
- Point 9 x (required)
-
Default 8 Range -10 to 10
About this input
The x of point 9, from -10 to 10. The points used must increase in x, each at least 0.01 above the one before.
- Point 1 y (required)
-
Default 0 Range -100 to 100
About this input
The y of point 1, from -100 to 100.
- Point 10 y (required)
-
Default 0 Range -100 to 100
About this input
The y of point 10, from -100 to 100.
- Point 5 y (required)
-
Default -0.8 Range -100 to 100
About this input
The y of point 5, from -100 to 100.
- Point 9 y (required)
-
Default 0 Range -100 to 100
About this input
The y of point 9, from -100 to 100.
- Clamped slope at the first point (required)
-
Default 0 Range -1000 to 1000
About this input
The slope the clamped cubic spline takes at the first point, from -1000 to 1000. Used only by the clamped spline.
- Target function (required)
-
Default None Allowed None, Sine, Runge, Exponential, Cubic
About this input
An optional function to compare the curve with: None, Sine sin(x), Runge 1/(1 + 25 x^2), Exponential exp(x) or Cubic x^3.
- Point 6 y (required)
-
Default 0 Range -100 to 100
About this input
The y of point 6, from -100 to 100.
- Point 7 y (required)
-
Default 0 Range -100 to 100
About this input
The y of point 7, from -100 to 100.
- Point 8 y (required)
-
Default 0 Range -100 to 100
About this input
The y of point 8, from -100 to 100.
- Number of points (required)
-
Default 5 Range 2 to 10
About this input
How many points the curve passes through, from 2 to 10. Only the first this many points are used; the others keep their values but are ignored.
- Point 1 x (required)
-
Default 0 Range -10 to 10
About this input
The x of point 1, from -10 to 10. The points used must increase in x, each at least 0.01 above the one before.
- Point 10 x (required)
-
Default 9 Range -10 to 10
About this input
The x of point 10, from -10 to 10. The points used must increase in x, each at least 0.01 above the one before.
- Challenge number (required)
-
Default 0 Range 0 to 5
About this input
0 for free play; 1 to 5 load one of the five challenges, whose scenario then replaces the inputs it fixes.
- Clamped slope at the last point (required)
-
Default 0 Range -1000 to 1000
About this input
The slope the clamped cubic spline takes at the last point, from -1000 to 1000. Used only by the clamped spline.
- Interpolation method (required)
-
Default Natural cubic Allowed Linear, Natural cubic, Clamped cubic, Polynomial
About this input
How the curve joins the points: Linear (straight segments), Natural cubic (a cubic spline with zero curvature at the ends), Clamped cubic (a cubic spline with the end slopes you set) or Polynomial (one polynomial through every point).
- Point 2 x (required)
-
Default 1 Range -10 to 10
About this input
The x of point 2, from -10 to 10. The points used must increase in x, each at least 0.01 above the one before.
- Point 6 x (required)
-
Default 5 Range -10 to 10
About this input
The x of point 6, from -10 to 10. The points used must increase in x, each at least 0.01 above the one before.
- Point 7 x (required)
-
Default 6 Range -10 to 10
About this input
The x of point 7, from -10 to 10. The points used must increase in x, each at least 0.01 above the one before.
- Point 8 x (required)
-
Default 7 Range -10 to 10
About this input
The x of point 8, from -10 to 10. The points used must increase in x, each at least 0.01 above the one before.
- Point 3 x (required)
-
Default 2 Range -10 to 10
About this input
The x of point 3, from -10 to 10. The points used must increase in x, each at least 0.01 above the one before.
- Point 4 x (required)
-
Default 3 Range -10 to 10
About this input
The x of point 4, from -10 to 10. The points used must increase in x, each at least 0.01 above the one before.
- Point 5 x (required)
-
Default 4 Range -10 to 10
About this input
The x of point 5, from -10 to 10. The points used must increase in x, each at least 0.01 above the one before.
Outputs
- Polynomial: Newton coefficients
-
No unit declared
About this output
The Newton coefficients of the interpolating polynomial, from divided differences. Polynomial only.
- Formula module versions
-
No unit declared
About this output
The formula modules the model is built from, with their versions.
- Points solved
-
No unit declared
About this output
The number of points actually solved.
- Overshoot beyond the points
-
No unit declared
About this output
How far the curve goes beyond the points' height range: above the highest point or below the lowest, measured at the 121 samples. 0 when it stays within.
- Method solved
-
No unit declared
About this output
The method actually solved: a challenge's given method, or yours.
- Largest value jump at a point
-
No unit declared
About this output
The largest jump in value between neighbouring segments at an interior point: rounding level for every method. Blank for the polynomial and for 2 points.
- Model version
-
No unit declared
About this output
The model version.
- Model Status
-
No unit declared
About this output
OK when the curve stays within 10% of the points' height range beyond them. CHECK when it overshoots further, as the polynomial does through many equally spaced points. NOT VALID names the input to fix.
- Clamped start slope solved
-
No unit declared
About this output
The start slope the clamped spline uses; blank for the other methods.
- Spline system: the tridiagonal sweep
-
No unit declared
About this output
The cubic spline's tridiagonal system, one row per point: h, alpha, then the forward sweep l, mu and z and the solved curvature coefficient C. Cubic methods only.
- Target function solved
-
No unit declared
About this output
The target function actually solved.
- Target function at the points
-
No unit declared
About this output
The target function at each point's x, for placing points exactly on it. Only with a target.
- Segment coefficients a + b t + c t^2 + d t^3
-
No unit declared
About this output
One row per segment: its number, its left and right x, and the coefficients a, b, c and d of a + b t + c t^2 + d t^3, with t measured from the left point. Blank for the polynomial.
- Root-mean-square error
-
No unit declared
About this output
The root-mean-square difference between the curve and the target over the 121 samples; blank with no target.
- Smoothness
-
No unit declared
About this output
How smooth the method makes the curve: Continuous (C0) for linear interpolation, Twice differentiable (C2) for the cubic splines, Smooth for the polynomial.
- Segments
-
No unit declared
About this output
The number of segments between the points: one fewer than the points.
- Largest slope jump at a point
-
No unit declared
About this output
The largest jump in slope at an interior point: a real jump for linear interpolation, rounding level for the cubic splines. Blank for the polynomial and for 2 points.
- Curve slope at the last point
-
No unit declared
About this output
The slope of the curve at the last point. The natural spline chooses it; the clamped spline takes yours. Blank for the polynomial.
- Continuity at the interior points
-
No unit declared
About this output
One row per interior point: the jumps in value, slope and curvature between the segments that meet there. Blank for the polynomial.
- Lowest curve value
-
No unit declared
About this output
The lowest value of the curve over its 121 samples.
- Highest curve value
-
No unit declared
About this output
The highest value of the curve over its 121 samples.
- Challenge goal
-
No unit declared
About this output
What the selected challenge asks.
- Challenge feedback
-
No unit declared
About this output
Whether the challenge is met, or a hint for what to try next.
- Challenge result
-
No unit declared
About this output
No challenge selected, MET or NOT MET.
- Challenge score
-
No unit declared
About this output
100 when the selected challenge is met, otherwise 0.
- Largest curvature jump at a point
-
No unit declared
About this output
The largest jump in curvature at an interior point: rounding level for the cubic splines, 0 for linear interpolation (straight segments have no curvature). Blank for the polynomial and for 2 points.
- Clamped end slope solved
-
No unit declared
About this output
The end slope the clamped spline uses; blank for the other methods.
- Where the largest error occurs
-
No unit declared
About this output
The x where the largest error occurs (the first, on a tie); blank with no target.
- Largest error against the target
-
No unit declared
About this output
The largest difference between the curve and the target function over the 121 samples; blank with no target.
- Curve slope at the first point
-
No unit declared
About this output
The slope of the curve at the first point (b of the first segment). The natural spline chooses it; the clamped spline takes yours. Blank for the polynomial.
- Curve: 121 samples computed by the model
-
No unit declared
About this output
The curve at 121 evenly spaced x from the first point to the last: x, the curve's value, its slope and its curvature, and with a target the target and the error. The page draws these rows exactly.
- Lowest point y
-
No unit declared
About this output
The lowest y among the points used.
- Highest point y
-
No unit declared
About this output
The highest y among the points used.
LogicCommons is in beta. If a result, label, or reference looks wrong, tell us here; we read every message.
Methodology
Purpose and model boundary
This lab draws a curve through 2 to 10 points that you place, by one of four methods: straight segments (linear interpolation), a natural cubic spline, a clamped cubic spline, or the single interpolating polynomial through every point. For the curve it returns its value, slope and curvature at 121 evenly spaced samples from the first point to the last, the coefficients of each segment, the jumps in value, slope and curvature where segments meet, how far the curve overshoots the points' height range, and, when you choose a target function, the error between the curve and that function. Five scored challenges ask you to choose a method, move points or set end slopes to meet a goal.
It is a learning lab for interpolation and splines. Every method is a direct calculation (one tridiagonal solve or one table of divided differences); there is no iteration and no tolerance to set. The curve is drawn only between the first and last points, never beyond them. The points and the numbers have no units.
The model is the calculation authority. The page sends the points and settings you choose to the model and draws only what the model returns, including the curve, its slope and its curvature; it computes no value of the curve itself.
Inputs and units
| Input | Meaning and unit |
|---|---|
| Number of points | How many points the curve passes through, a whole number from 2 to 10 (default 5). Only the first this many points are used; the others keep their values but are ignored, even when blank or out of range. |
| Point 1 x to Point 10 x | The x of each point, from -10 to 10 (defaults 0, 1, 2, ... 9). The points used must increase in x, each at least 0.01 above the one before. |
| Point 1 y to Point 10 y | The y of each point, from -100 to 100 (defaults 0, 0.8, 0.9, 0.1, -0.8, then 0). |
| Interpolation method | Linear (straight segments), Natural cubic (a cubic spline with zero curvature at both ends; the default), Clamped cubic (a cubic spline with the end slopes you set) or Polynomial (one polynomial through every point). |
| Clamped slope at the first point | The slope the clamped spline takes at the first point, from -1000 to 1000 (default 0). Used only by the clamped spline. |
| Clamped slope at the last point | The slope the clamped spline takes at the last point, from -1000 to 1000 (default 0). Used only by the clamped spline. |
| Target function | An optional function to compare the curve with: None (the default), Sine sin(x), Runge 1/(1 + 25x²), Exponential exp(x) or Cubic x³. |
| Challenge number | 0 for free play; 1 to 5 load one of the five challenges, whose givens then replace the inputs it fixes. |
Sign conventions: x increases to the right and y upward. A slope is the change in y per unit of x, so a positive slope rises to the right.
Where each input is set:
- On the canvas only: the interpolation method, chosen with the method switch above the drawing.
- On the canvas and in the panel: the points. On the canvas you drag a point, click empty space to add one, or select a point and press Delete to remove it (2 to 10 points); the points keep their order in x. In the panel the same points are the Control points table, where Add point adds a row; the number of points follows the rows. With a target function, a button on the canvas moves every point's y onto the target, using the target values the model returns at the points' x.
- On the canvas and in the panel: the two clamped end slopes. With the clamped spline chosen, a slope handle at each end of the curve can be dragged.
- In the panel: the target function and the challenge number.
Governing relationships
The points used are (x₁, y₁) to (xₙ, yₙ), with spacing hᵢ = xᵢ₊₁ − xᵢ. Except for the polynomial, every segment i (from xᵢ to xᵢ₊₁) is a cubic in t = x − xᵢ:
Sᵢ(x) = aᵢ + bᵢ t + cᵢ t² + dᵢ t³
Linear. aᵢ = yᵢ, bᵢ = (yᵢ₊₁ − yᵢ)/hᵢ, and cᵢ = dᵢ = 0: a straight segment between neighbouring points.
Cubic splines. The model solves for Cᵢ, the c coefficient at each point, which is half the second derivative there (Cᵢ = S''(xᵢ)/2), with a tridiagonal system solved by a forward sweep and back substitution:
- αᵢ = 3(yᵢ₊₁ − yᵢ)/hᵢ − 3(yᵢ − yᵢ₋₁)/hᵢ₋₁ for the interior points i = 2 to n − 1.
- Natural spline: the curvature is zero at both ends (l₁ = 1, μ₁ = 0, z₁ = 0 at the start; Cₙ = 0 at the end).
- Clamped spline: the end slopes are your two slopes s₀ and s₁. At the start α₁ = 3(y₂ − y₁)/h₁ − 3s₀, l₁ = 2h₁, μ₁ = 0.5, z₁ = α₁/l₁; at the end αₙ = 3s₁ − 3(yₙ − yₙ₋₁)/hₙ₋₁, lₙ = hₙ₋₁(2 − μₙ₋₁) and Cₙ = zₙ = (αₙ − hₙ₋₁ zₙ₋₁)/lₙ.
- Forward sweep for i = 2 to n − 1: lᵢ = 2(xᵢ₊₁ − xᵢ₋₁) − hᵢ₋₁ μᵢ₋₁, μᵢ = hᵢ/lᵢ, zᵢ = (αᵢ − hᵢ₋₁ zᵢ₋₁)/lᵢ.
- Back substitution for j = n − 1 down to 1: Cⱼ = zⱼ − μⱼ Cⱼ₊₁.
- Segment coefficients: aᵢ = yᵢ, bᵢ = (yᵢ₊₁ − yᵢ)/hᵢ − hᵢ(Cᵢ₊₁ + 2Cᵢ)/3, cᵢ = Cᵢ, dᵢ = (Cᵢ₊₁ − Cᵢ)/(3hᵢ).
With 2 points the natural spline is the straight line through them, and the clamped spline is a single cubic with the two end slopes you set.
Polynomial. The single polynomial of degree n − 1 through all n points, in Newton form. Its coefficients come from the table of divided differences, F(i, 0) = yᵢ and F(i, j) = (F(i, j − 1) − F(i − 1, j − 1))/(xᵢ − xᵢ₋ⱼ), and Nⱼ = F(j + 1, j) for j = 0 to n − 1. It is evaluated by nested multiplication (Horner's rule):
P(x) = N₀ + (x − x₁)(N₁ + (x − x₂)(N₂ + … + (x − xₙ₋₁)Nₙ₋₁))
Sampling. The curve is evaluated at 121 samples xₛ = x₁ + s(xₙ − x₁)/120, s = 0 to 120. For the linear and spline methods each sample uses the segment it falls in, with value a + t(b + t(c + t d)), slope S' = b + t(2c + 3d t) and curvature S'' = 2c + 6d t. For the polynomial the value, slope and curvature come from the same nested evaluation carried with its first and second derivatives.
Continuity. At each interior point the model ends the left segment at t = hᵢ₋₁ and compares it with the right segment at t = 0: the value jump, the slope jump and the curvature jump (the curvature jump is measured on S'' = 2c + 6d t).
Overshoot and error. The overshoot is max(0, highest curve sample − highest point y, lowest point y − lowest curve sample). With a target function f, the error at each sample is S(xₛ) − f(xₛ); the largest error is the largest |S − f| over the samples, and the root-mean-square error is √(Σ(S − f)²/121).
Calculation sequence
The model works through the relationships above in this order:
- It checks the inputs in the order of the status table under Errors and warnings. Under NOT VALID every result is blank.
- It fixes what is solved: your inputs, or in a challenge the challenge's givens where it fixes them.
- It builds the curve by the chosen method: the linear segments, the tridiagonal sweep and back substitution of a cubic spline, or the divided differences of the polynomial.
- It evaluates the curve, its slope and its curvature at the 121 samples, and the jumps at the interior points.
- It finds the overshoot and, with a target function, the error at each sample, the largest error and the root-mean-square error.
- It sets the status and, in a challenge, scores the challenge.
Outputs and interpretation
- Status: OK, CHECK or NOT VALID (see Validation and status logic and Errors and warnings).
- What was solved: the method, the number of points, the target function and, for the clamped spline, the two end slopes actually used. In a challenge these are the challenge's givens where it fixes them.
- Segments (one fewer than the points) and smoothness: Continuous (C0) for linear interpolation, Twice differentiable (C2) for both cubic splines, Smooth (polynomial) for the polynomial.
- Curve slope at the first and last points. The natural spline chooses these slopes; the clamped spline takes yours. Blank for the polynomial.
- Largest value, slope and curvature jumps over the interior points. For the cubic splines all three are at rounding level; linear interpolation shows real slope jumps and a curvature jump of 0, because straight segments have no curvature. Blank for the polynomial and for 2 points.
- Lowest and highest point y, lowest and highest curve value, and the overshoot beyond the points' height range: 0 when the curve stays within it. The overshoot is measured against the points, never against the target.
- Error against the target: the largest error, where it occurs (the first sample x on a tie), and the root-mean-square error. All blank with no target. Where the largest error occurs is also blank when the largest error is at rounding level (at most 1×10⁻⁹ times the largest of 1 and the points' |y|), because a rounding-level maximum has no meaningful location.
- Curve samples: 121 rows of x, the curve, its slope, its curvature, and with a target the target and the error. The page draws these rows exactly, for the curve and for its slope and curvature charts.
- Coefficients of each piece: segment, x left, x right and a, b, c, d of a + b t + c t² + d t³, with t measured from the left point. Blank for the polynomial.
- Continuity at the inner knots: for each interior point, its x and the value, slope and curvature jumps. Blank for the polynomial.
- The tridiagonal sweep: one row per point with h, α, l, μ, z and the solved C. Cubic splines only; h is blank on the last row, and α is blank at the ends of the natural spline.
- Newton coefficients: j and Nⱼ. Polynomial only.
- The target at the points: each point's x and f(x), for placing points exactly on the target. Only with a target.
- Challenge result, score, goal and feedback: No challenge selected, MET or NOT MET; a score of 100 when met, otherwise 0; the goal text and a hint.
Challenges
Set the challenge number to 1 to 5. The challenge's givens replace the inputs it fixes, and only the remaining inputs are yours to change. Each is scored by the model as MET or NOT MET.
- Tame the overshoot. Five step-shaped points are given, with no target. Choose a method, and for the clamped spline its end slopes, so that the curve stays within the height of the points (an overshoot of at most 0.01).
- Follow the sine. Five x positions from 0 to 6, the natural spline and the Sine target are given. Move the points' heights so the spline follows sin(x) within 0.1 at every sample.
- Runge's warning. Nine equally spaced points on the Runge curve are given, with the Runge target. Choose a method whose curve stays within 0.06 of the Runge curve at every sample.
- Set the end slopes. Four points on y = x³, the clamped spline and the Cubic target are given. Set the two end slopes so the spline matches the cubic within 0.001.
- Four points for the exponential. Only the Exponential target is given. Use at most 4 points that cover x = 0 to 2 (the first x at most 0 and the last at least 2), and any method and slopes, to follow exp(x) within 0.02.
Validation and status logic
The status reads the first message in the table under Errors and warnings that applies: the NOT VALID input checks first, then the CHECK, then OK. CHECK still returns every result: it warns that the curve swings well beyond the points, as the polynomial does through many equally spaced points.
Assumptions and limitations
- The curve, the overshoot and the error are sampled at 121 evenly spaced points between the first and last points only. A larger error or overshoot between two samples, or beyond the end points, is not counted.
- Points close together in x but far apart in y give very large cubic coefficients, and the polynomial through many equally spaced points can swing far beyond the data. Both are shown, not hidden.
- The CHECK rule allows a rounding margin of 1×10⁻⁹ times the largest of 1 and the points' |y|; an overshoot sitting exactly on the 10% threshold may read either way.
- The target functions are fixed: sin(x), 1/(1 + 25x²), exp(x) and x³.
Restrictions and non-computing states
- 2 to 10 points; x from -10 to 10, increasing, each at least 0.01 above the one before; y from -100 to 100; clamped end slopes from -1000 to 1000. Only the first "Number of points" points are checked and used. The range and spacing checks always apply to your own entered points and count, also in a challenge whose given points replace them.
- Under NOT VALID the results and tables read blank, and a selected challenge reads NOT MET.
- Rows beyond the points used read blank, and the page draws only the rows that hold values.
Errors and warnings
The status messages, in the order they are checked:
| Status | When |
|---|---|
| NOT VALID: the number of points must be a whole number from 2 to 10 | The number of points is not a whole number from 2 to 10. |
| NOT VALID: choose an interpolation method from the list | The method is not one of the four listed. |
| NOT VALID: each point used needs x from -10 to 10 and y from -100 to 100 | A point used is outside the x or y range. |
| NOT VALID: the x values must increase from point to point, at least 0.01 apart | Two consecutive points used are less than 0.01 apart in x, or out of order. |
| NOT VALID: the end slopes must be from -1000 to 1000 | Either end slope is outside its range (checked for every method). |
| NOT VALID: choose a target function from the list | The target function is not one of the five listed. |
| NOT VALID: the challenge number must be a whole number from 0 to 5 | The challenge number is not 0 to 5. |
| CHECK: the curve overshoots the points by more than 10% of their height range | The overshoot is more than 10% of (highest point y − lowest point y), plus the rounding margin. |
| OK | None of the above. |
References
This laboratory is an educational model of curves drawn through a set of points. It compares linear interpolation, the natural cubic spline (zero curvature at both ends), the clamped cubic spline (set end slopes) and the single interpolating polynomial of degree n - 1 through all n points. The spline coefficients come from one tridiagonal linear system solved by a forward sweep and back substitution. The polynomial is built in Newton form from divided differences, which gives the same polynomial as the Lagrange form, and is evaluated by Horner's rule. Against a chosen target function, the laboratory shows the interpolation error and the oscillation of a high-degree polynomial through equally spaced points.
Sources and further reading
- Lagrange and Newton interpolation, divided differences, and natural and clamped cubic splines with their algorithms: R. L. Burden, J. D. Faires and A. M. Burden, Numerical Analysis, 10th edition, Cengage Learning, 2016, chapter 3, Interpolation and Polynomial Approximation.
- Cubic spline interpolation and its end conditions: C. de Boor, A Practical Guide to Splines, revised edition, Applied Mathematical Sciences 27, Springer, 2001. Springer
- The oscillation of polynomials interpolating equally spaced points, now called the Runge phenomenon: C. Runge, "Über empirische Funktionen und die Interpolation zwischen äquidistanten Ordinaten", Zeitschrift für Mathematik und Physik 46, 1901.
- The cubic spline and its tridiagonal system: E. W. Weisstein, "Cubic Spline", MathWorld, Wolfram Research. MathWorld
- The interpolating polynomial in Lagrange form: E. W. Weisstein, "Lagrange Interpolating Polynomial", MathWorld, Wolfram Research. MathWorld
No table or text from any of these publications is reproduced, and none of their authors or publishers has reviewed or endorses this laboratory.
This laboratory is for learning. Its results hold only within its stated ranges; check any curve you rely on with an independent method.
Found a problem, or have an idea?
Tell us if a result looks wrong, a label is unclear, or something is missing. We read every message.