Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| documentation:language_reference:objects:interpolatingfunction:functions:bspline [2019/09/12 15:08] – created Martin Brass | documentation:language_reference:objects:interpolatingfunction:functions:bspline [2026/11/16 23:20] (current) – Maurits W. Haverkort | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| {{indexmenu_n> | {{indexmenu_n> | ||
| - | ====== | + | ====== |
| + | ;;# | ||
| + | <color # | ||
| + | ;;# | ||
| ### | ### | ||
| - | InterpolatingFunction.BSpline(x, | + | //f = InterpolatingFunction.BSpline(x, |
| + | $$ | ||
| + | f(x) = \sum_{j=1}^{N} c_j B_j(x), | ||
| + | $$ | ||
| + | with the coefficients $c_j$ such that $f(x_i) = y_i$ for all $N$ points. Between two knots $f$ is a polynomial of degree $n$, and $f$ and its derivatives up to order $n - 1$ are continuous. | ||
| + | ### | ||
| + | |||
| + | ===== Input ===== | ||
| + | |||
| + | * //x// : a table of $N$ different real numbers, the points. They need not be sorted; the points are sorted together with their values. | ||
| + | * //y// : a table of $N$ real numbers, the values at the points. | ||
| + | * //n// : Integer, the degree, $1 \leq n \leq N - 1$. | ||
| + | |||
| + | ===== Output ===== | ||
| + | |||
| + | * //f// : an interpolating function of type //" | ||
| + | |||
| + | ### | ||
| + | A B-spline | ||
| + | ### | ||
| + | |||
| + | ### | ||
| + | A B-spline | ||
| + | ### | ||
| + | |||
| + | ;;# | ||
| + | <color # | ||
| + | ;;# | ||
| + | |||
| + | ### | ||
| + | //-f//, and the sum and difference of two B-splines with the same degree and knots, act on the coefficients and are exact. B-splines of any degree are integrated exactly by // | ||
| ### | ### | ||
| ===== Example ===== | ===== Example ===== | ||
| + | ;;# | ||
| + | <color # | ||
| + | ;;# | ||
| + | ### | ||
| + | $\sin(x)$ sampled at 11 points on $[0, \pi]$, interpolated with degrees 1 to 7: every two degrees the error of the function and of its second derivative drop by more than an order of magnitude. The second part shows the properties of a B-spline of degree 3 through points of $x^2$, which it reproduces exactly. | ||
| + | ### | ||
| + | |||
| + | ==== Input ==== | ||
| <code Quanty Example.Quanty> | <code Quanty Example.Quanty> | ||
| - | BS = InterpolatingFunction.BSpline({1,1.5,2,2.5,3},{1,2,4,3,9},2) | + | -- sin(x) sampled at 11 points on [0, pi], interpolated by B-splines of degree 1 to 7 |
| + | x, y = {}, {} | ||
| + | for i = 0, 10 do x[i+1] = i*math.pi/10; y[i+1] = math.sin(x[i+1]) end | ||
| + | for _, n in ipairs({1, 2, 3, 5, 7}) do | ||
| + | local f, e0, e2 = InterpolatingFunction.BSpline(x, | ||
| + | for i = 0, 1000 do | ||
| + | local t = i*math.pi/ | ||
| + | e0 = math.max(e0, | ||
| + | if n >= 2 then e2 = math.max(e2, | ||
| + | end | ||
| + | print(string.format(" | ||
| + | n, #f.knots, e0, n >= 2 and string.format(" | ||
| + | end | ||
| + | |||
| + | -- a B-spline of degree 3 through 6 points | ||
| + | g = InterpolatingFunction.BSpline({0, 1, 2, 3, 4, 5}, {0, 1, 4, 9, 16, 25}, 3) | ||
| + | print(" | ||
| + | print(" | ||
| + | print(" | ||
| + | c = g.coefficients | ||
| + | for i = 1, #c do c[i] = string.format(" | ||
| + | print(" | ||
| + | print(" | ||
| </ | </ | ||
| + | |||
| + | <file Quanty_Output Example.out> | ||
| + | degree 1: 11 knots, max |f - sin| = 1.2e-02, max |f'' | ||
| + | degree 2: 10 knots, max |f - sin| = 1.4e-03, max |f'' | ||
| + | degree 3: 9 knots, max |f - sin| = 8.8e-05, max |f'' | ||
| + | degree 5: 7 knots, max |f - sin| = 7.0e-06, max |f'' | ||
| + | degree 7: 5 knots, max |f - sin| = 5.2e-07, max |f'' | ||
| + | x = 0, 1, 2, 3, 4, 5 | ||
| + | y = 0, 1, 4, 9, 16, 25 | ||
| + | knots = 0, 2, 3, 5 | ||
| + | coefficients = 0.0000, 0.0000, 2.0000, 10.3333, 18.3333, 25.0000 | ||
| + | g(2.5) = 6.25, type BSpline, degree 3 | ||
| + | </ | ||
| ===== Table of contents ===== | ===== Table of contents ===== | ||
| - | {{indexmenu> | + | {{indexmenu> |
| + | |||