Report a bug
If you spot a problem with this page, click here to create a GitHub issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

mir.interpolate.utility

struct ParabolaKernel(T);

ParabolaKernel!(Unqual!(typeof(X.init - Y.init))) parabolaKernel(X, Y)(in X x0, in X x1, in X x2, in Y y0, in Y y1, in Y y2);
Quadratic function structure
T a;
T b;
T c;
this(T a, T b, T c);
this(T x0, T x1, T x2, T y0, T y1, T y2);
Builds parabola given three points
static ParabolaKernel fromFirstDerivative(T x0, T x1, T y0, T y1, T d1);
Parameters:
T x0 x0
T x1 x1
T y0 f(x0)
T y1 f(x1)
T d1 f'(x1)
const auto opCall(uint derivative = 0)(T x)
if (derivative <= 2);
alias withDerivative = opCall!1;
alias withTwoDerivatives = opCall!2;
Unqual!(typeof(X.init - Y.init))[3] parabolaDerivatives(X, Y)(in X x0, in X x1, in X x2, in Y y0, in Y y1, in Y y2);
Returns:
[f'(x0), f'(x1), f'(x2)]
Examples:
import mir.math.common: approxEqual;

alias f = (double x) => 3 * x ^^ 2 + 7 * x + 5;
auto x0 = 4;
auto x1 = 9;
auto x2 = 20;
auto p = parabolaKernel(x0, x1, x2, f(x0), f(x1), f(x2));

assert(p.a.approxEqual(3));
assert(p.b.approxEqual(7));
assert(p.c.approxEqual(5));
assert(p(10).approxEqual(f(10)));
Examples:
import mir.math.common: approxEqual;

alias f = (double x) => 3 * x ^^ 2 + 7 * x + 5;
alias d = (double x) => 2 * 3 * x + 7;
auto x0 = 4;
auto x1 = 9;
auto p = ParabolaKernel!double.fromFirstDerivative(x0, x1, f(x0), f(x1), d(x1));

assert(p.a.approxEqual(3));
assert(p.b.approxEqual(7));
assert(p.c.approxEqual(5));
struct CubicKernel(T);
Cubic function structure
Examples:
import mir.math.common: approxEqual;

alias f = (double x) => 3 * x ^^ 3 + 7 * x ^^ 2 + 5 * x + 10;
alias d = (double x) => 3 * 3 * x ^^ 2 + 2 * 7 * x + 5;
alias s = (double x) => 6 * 3 * x + 2 * 7;
auto x0 = 4;
auto x1 = 9;
auto p = CubicKernel!double.fromSecondAndFirstDerivative(x0, x1, f(x0), f(x1), s(x0), d(x1));

assert(p.a.approxEqual(3));
assert(p.b.approxEqual(7));
assert(p.c.approxEqual(5));
assert(p.d.approxEqual(10));
assert(p(13).approxEqual(f(13)));
assert(p.opCall!1(13)[1].approxEqual(d(13)));
assert(p.opCall!2(13)[2].approxEqual(s(13)));
assert(p.opCall!3(13)[3].approxEqual(18));
T a;
T b;
T c;
T d;
this(T a, T b, T c, T d);
static CubicKernel fromSecondAndFirstDerivative(T x0, T x1, T y0, T y1, T dd0, T d1);
Parameters:
T x0 x0
T x1 x1
T y0 f(x0)
T y1 f(x1)
T dd0 f''(x0)
T d1 f'(x1)
const auto opCall(uint derivative = 0)(T x)
if (derivative <= 3);
alias withDerivative = opCall!1;
alias withTwoDerivatives = opCall!2;