| Both sides previous revisionPrevious revisionNext revision | Previous revision |
| documentation:language_reference:objects:interpolatingfunction:start [2026/11/13 19:06] – Maurits W. Haverkort | documentation:language_reference:objects:interpolatingfunction:start [2026/11/17 07:32] (current) – Maurits W. Haverkort |
|---|
| {{indexmenu_n>999}} | {{indexmenu_n>999}} |
| ====== Interpolating function ====== | ====== Interpolating function ====== |
| | ;;# |
| | <color #ed1c24>Modified in 0.9.1</color> |
| | ;;# |
| |
| ### | ### |
| ^ Type ^ Made by ^ Between the points ^ Continuous ^ Exact for ^ | ^ Type ^ Made by ^ Between the points ^ Continuous ^ Exact for ^ |
| | //"Spline"// | //[[documentation:language_reference:objects:interpolatingfunction:functions:spline|InterpolatingFunction.Spline(x, y)]]// | cubic polynomials | $f$, $f'$, $f''$ | straight lines; cubics when the slopes at the two ends are given | | | //"Spline"// | //[[documentation:language_reference:objects:interpolatingfunction:functions:spline|InterpolatingFunction.Spline(x, y)]]// | cubic polynomials | $f$, $f'$, $f''$ | straight lines; cubics when the slopes at the two ends are given | |
| | //"HermiteCSpline"// | //[[documentation:language_reference:objects:interpolatingfunction:functions:hermitecspline|InterpolatingFunction.HermiteCSpline(x, y)]]// | cubic polynomials, no overshoot | $f$, $f'$ | straight lines; cubics when the slopes at all points are given | | | //"HermiteCSpline"// | //[[documentation:language_reference:objects:interpolatingfunction:functions:monotoniccspline|InterpolatingFunction.HermiteCSpline(x, y)]]// | cubic polynomials, no overshoot | $f$, $f'$ | straight lines; cubics when the slopes at all points are given | |
| | //"BSpline"// | //[[documentation:language_reference:objects:interpolatingfunction:functions:bspline|InterpolatingFunction.BSpline(x, y, n)]]// | polynomials of degree $n$ | $f$ up to $f^{(n-1)}$ | polynomials up to degree $n$ | | | //"BSpline"// | //[[documentation:language_reference:objects:interpolatingfunction:functions:bspline|InterpolatingFunction.BSpline(x, y, n)]]// | polynomials of degree $n$ | $f$ up to $f^{(n-1)}$ | polynomials up to degree $n$ | |
| | //"DKBSpline"// | //[[documentation:language_reference:functions:calculateatomicbasisfunctions|CalculateAtomicBasisFunctions()]]// | one component of a radial Dirac spinor | all derivatives | (not made from data) | | | //"DKBSpline"// | //[[documentation:language_reference:functions:calculateatomicbasisfunctions|CalculateAtomicBasisFunctions()]]// | one component of a radial Dirac spinor | all derivatives | (not made from data) | |
| * Data with known derivatives: //HermiteCSpline// with the slopes at all points. | * Data with known derivatives: //HermiteCSpline// with the slopes at all points. |
| * Straight lines between the points: a //BSpline// of degree 1. | * Straight lines between the points: a //BSpline// of degree 1. |
| | |
| ### | ### |
| |
| ===== Example ===== | ===== Example ===== |
| | ;;# |
| | <color #ed1c24>Modified in 0.9.1</color> |
| | ;;# |
| |
| ### | ### |
| |
| ### | ### |
| //[[documentation:language_reference:objects:interpolatingfunction:functions:hermitecspline|InterpolatingFunction.HermiteCSpline(x, y)]]// makes a cubic Hermite spline: on every interval the cubic polynomial with the values and the slopes at its two ends. The function and its first derivative are continuous, the second derivative jumps at the data points. Without slopes, the slopes are estimated from the neighbouring points and limited (Fritsch–Carlson) such that the interpolation is monotone wherever the data is: there is no overshoot, and a flat part of the data stays flat. With the slopes given at every point, //InterpolatingFunction.HermiteCSpline(x, y, m)//, the slopes are used as they are. The curve between two points only depends on the points nearby, so a change of one data point changes the function only locally. | //[[documentation:language_reference:objects:interpolatingfunction:functions:monotoniccspline|InterpolatingFunction.HermiteCSpline(x, y)]]// makes a cubic Hermite spline: on every interval the cubic polynomial with the values and the slopes at its two ends. The function and its first derivative are continuous, the second derivative jumps at the data points. Without slopes, the slopes are estimated from the neighbouring points and limited (Fritsch–Carlson) such that the interpolation is monotone wherever the data is: there is no overshoot, and a flat part of the data stays flat. With the slopes given at every point, //InterpolatingFunction.HermiteCSpline(x, y, m)//, the slopes are used as they are. The curve between two points only depends on the points nearby, so a change of one data point changes the function only locally. |
| ### | ### |
| |
| |
| ===== DKBSpline ===== | ===== DKBSpline ===== |
| | ;;# |
| | <color #ed1c24>New in 0.9.1</color> |
| | ;;# |
| |
| ### | ### |
| An interpolating function of type //"DKBSpline"// is not made from data. It is one of the two components of a radial Dirac spinor, as returned by //[[documentation:language_reference:functions:calculateatomicbasisfunctions|CalculateAtomicBasisFunctions()]]// and //DiracRadialSolve()//: the large component $G = P(r) = r g(r)$ or the small component $F = Q(r) = r f(r)$ of an orbital with quantum number $\kappa$. The two belong together. They are expanded in a dual kinetic balance (DKB) B-spline basis (V. M. Shabaev et al., [[https://doi.org/10.1103/PhysRevLett.93.130405|Phys. Rev. Lett. 93, 130405 (2004)]]), with the two sets of coefficients $a_j$ and $b_j$ of the orbital, | An interpolating function of type //"DKBSpline"// is not made from data. It is one of the two components of a radial Dirac spinor, as returned by //[[documentation:language_reference:functions:calculateatomicbasisfunctions|CalculateAtomicBasisFunctions()]]//: the large component $G = P(r) = r g(r)$ or the small component $F = Q(r) = r f(r)$ of an orbital with quantum number $\kappa$. The two belong together. They are expanded in a dual kinetic balance (DKB) B-spline basis (V. M. Shabaev et al., [[https://doi.org/10.1103/PhysRevLett.93.130405|Phys. Rev. Lett. 93, 130405 (2004)]]), with the two sets of coefficients $a_j$ and $b_j$ of the orbital, |
| $$ | $$ |
| \begin{eqnarray} | \begin{eqnarray} |
| * Because of the $1/r$ terms the function is not a polynomial between the knots. //f.degree// is the degree of the B-splines. Derivatives of every order are calculated exactly from the B-splines. | * Because of the $1/r$ terms the function is not a polynomial between the knots. //f.degree// is the degree of the B-splines. Derivatives of every order are calculated exactly from the B-splines. |
| * //f.x// are the radial points of the quadrature of the atom, //f.knots// the knots of the B-splines, from 0 to the end of the radial grid. | * //f.x// are the radial points of the quadrature of the atom, //f.knots// the knots of the B-splines, from 0 to the end of the radial grid. |
| * Arithmetic (//G + F//, //G * F//, ...) and comparison are not available: the sum of two components is no longer a component of a spinor. | * In arithmetic (//G + F//, //G * F//, ...) and comparison a //DKBSpline// acts as the //BSpline// of its degree through its values on //f.x//, and the result is a //BSpline//: the sum or product of two components is no longer a component of a spinor. The points are dense, so integrals of products, for example the overlap $\int (G_a G_b + F_a F_b) \, \mathrm{d}r$, are exact to rounding. |
| ### | ### |
| |
| <code Quanty Example.Quanty> | <code Quanty Example.Quanty> |
| -- the 2p orbitals of Ne: the large components G and the small components F | -- the 2p orbitals of Ne: the large components G and the small components F |
| G, F, x, Atom = CalculateAtomicBasisFunctions(10) | G, F, Atom = CalculateAtomicBasisFunctions(10) |
| c, r = PhysicalConstants.cAU.value, 1 | c, r = PhysicalConstants.cAU.value, 1 |
| for i, o in ipairs(Atom.Orbitals) do | for i, o in ipairs(Atom.Orbitals) do |
| print(string.format("type %s, degree %d, %d knots from %g to %g, %d points x", | print(string.format("type %s, degree %d, %d knots from %g to %g, %d points x", |
| G[1].type, G[1].degree, #G[1].knots, G[1].knots[1], G[1].knots[#G[1].knots], #G[1].x)) | G[1].type, G[1].degree, #G[1].knots, G[1].knots[1], G[1].knots[#G[1].knots], #G[1].x)) |
| ok, message = pcall(function() return G[1] + G[2] end) | -- the overlaps of 1s1/2 and 2s1/2: the products are BSplines on the points x |
| print(message) | print(string.format("<1s|1s> - 1 = %.1e, <1s|2s> = %.1e, type of G * G: %s", InterpolatingFunction.Integrate(G[1]*G[1] + F[1]*F[1]) - 1, |
| | InterpolatingFunction.Integrate(G[1]*G[2] + F[1]*F[2]), (G[1]*G[2]).type)) |
| </code> | </code> |
| |
| 2p3/2 kappa -2 G(1) = 0.831407 F(1) = -0.0081275 (G'(1) + kappa G(1))/(2c) = -0.0081277 | 2p3/2 kappa -2 G(1) = 0.831407 F(1) = -0.0081275 (G'(1) + kappa G(1))/(2c) = -0.0081277 |
| type DKBSpline, degree 8, 121 knots from 0 to 40, 1560 points x | type DKBSpline, degree 8, 121 knots from 0 to 40, 1560 points x |
| Example.Quanty:13: Error: f + g is not yet supported for interpolating functions of type DKBSpline | <1s|1s> - 1 = -2.1e-15, <1s|2s> = -1.8e-16, type of G * G: BSpline |
| </file> | </file> |
| |
| ===== Evaluation ===== | ===== Evaluation ===== |
| | ;;# |
| | <color #ed1c24>Modified in 0.9.1</color> |
| | ;;# |
| |
| ### | ### |
| * //f({t1, t2, ...})//, //f({t1, t2, ...}, k)// : a table of values. This is faster when the points are in increasing order. | * //f({t1, t2, ...})//, //f({t1, t2, ...}, k)// : a table of values. This is faster when the points are in increasing order. |
| Outside $[x_1, x_N]$ (for a //DKBSpline// outside its knots) the value and all derivatives are 0. | Outside $[x_1, x_N]$ (for a //DKBSpline// outside its knots) the value and all derivatives are 0. |
| | |
| ### | ### |
| |
| ===== Properties ===== | ===== Properties ===== |
| | ;;# |
| | <color #ed1c24>Modified in 0.9.1</color> |
| | ;;# |
| |
| ### | ### |
| * //f.x//, //f.y// : the points the function is given on and its values there. For //Spline//, //HermiteCSpline// and //BSpline// these are the data points; a //BSpline// made from coefficients (for example a nonrelativistic radial function of //CalculateAtomicBasisFunctions//) gives its knots. A //DKBSpline// gives the radial points of the quadrature of the atom. | * //f.x//, //f.y// : the points the function is given on and its values there. For //Spline//, //HermiteCSpline// and //BSpline// these are the data points; a //BSpline// made from coefficients gives its knots. The radial functions and the potentials of //[[documentation:language_reference:functions:calculateatomicbasisfunctions|CalculateAtomicBasisFunctions()]]//, of type //DKBSpline// or //BSpline//, give the radial points of the quadrature of the atom. |
| * //f.knots// : the points where the polynomial pieces join. For the cubic splines these are the data points. | * //f.knots// : the points where the polynomial pieces join. For the cubic splines these are the data points. |
| * //f.degree// : the polynomial degree of the pieces, 3 for the cubic splines. | * //f.degree// : the polynomial degree of the pieces, 3 for the cubic splines. |
| * //f.coefficients// : (//BSpline// only) the B-spline coefficients, one per data point. | * //f.coefficients// : (//BSpline// only) the B-spline coefficients, one per data point. |
| * //f.type// : the type, //"Spline"//, //"HermiteCSpline"//, //"BSpline"// or //"DKBSpline"//. For the first three this is the name of the function that made it, so //InterpolatingFunction[f.type]// makes a function of the same kind. | * //f.type// : the type, //"Spline"//, //"HermiteCSpline"//, //"BSpline"// or //"DKBSpline"//. For the first three this is the name of the function that made it, so //InterpolatingFunction[f.type]// makes a function of the same kind. |
| | |
| ### | ### |
| |
| |
| ===== Arithmetic ===== | ===== Arithmetic ===== |
| | ;;# |
| | <color #ed1c24>Modified in 0.9.1</color> |
| | ;;# |
| |
| ### | ### |
| For two interpolating functions //f// and //g//, //-f//, //f + g//, //f - g//, //f * g//, //f / g//, //f ^ n// (with //n// a number) and the composition //f .. g//, $f(g(x))$, are again interpolating functions, of the type of //f//. Both operands must be interpolating functions; a number is not converted. The result is made on the data points of //f// and //g// together (//f ^ n// and //f .. g// on those of //f//), through the exact values $f(x_i) + g(x_i)$, ... at these points, and is interpolated between them by the type of //f//. It is therefore exact at the points, and in general a new approximation between them. Exact everywhere are: | For two interpolating functions //f// and //g//, //-f//, //f + g//, //f - g//, //f * g//, //f / g//, //f ^ n// (with //n// a number) and the composition //f .. g//, $f(g(x))$, are again interpolating functions, of the type of //f//; a //DKBSpline// acts as the //BSpline// through its values on its points //f.x//, so its results are //BSpline//s. Both operands must be interpolating functions; a number is not converted. The result is made on the data points of //f// and //g// together (//f ^ n// and //f .. g// on those of //f//), through the exact values $f(x_i) + g(x_i)$, ... at these points, and is interpolated between them by the type of //f//. It is therefore exact at the points, and in general a new approximation between them. Exact everywhere are: |
| * //f + g// and //f - g// of two //Spline//s: the sum of two cubic splines is a cubic spline on the points of both. | * //f + g// and //f - g// of two //Spline//s: the sum of two cubic splines is a cubic spline on the points of both. |
| * //-f//, and //f + g// and //f - g// of two //BSpline//s of the same degree and knots, which act on the coefficients. | * //-f//, and //f + g// and //f - g// of two //BSpline//s of the same degree and knots, which act on the coefficients. |
| For a //HermiteCSpline// even a sum is a new interpolation, with new slopes. //f == g// is true when //f// and //g// are of the same type and have the same points and values (//BSpline//: the same degree, knots and coefficients) to a relative precision of $10^{-14}$. | For a //HermiteCSpline// even a sum is a new interpolation, with new slopes. //f == g// is true when //f// and //g// are of the same type and have the same points and values (//BSpline//: the same degree, knots and coefficients) to a relative precision of $10^{-14}$. |
| | |
| ### | ### |
| |
| |
| ===== Table of contents ===== | ===== Table of contents ===== |
| {{indexmenu>.#1|msort}} | {{indexmenu>.#2|msort}} |
| |
| |