Polynomial

Polynomial callable ref-counted structure.

Constructors

this
this(RCArray!(const F) coefficients)

Members

Templates

opCall
template opCall(uint derivative = 0)

Variables

coefficients
RCArray!(const F) coefficients;

Examples

import mir.math.common: approxEqual;
import mir.rc.array;
auto a = rcarray!(const double)(3.0, 4.5, 1.9, 2);
auto p = a.polynomial;

alias f = (x) => 3.0 + 4.5 * x^^1 + 1.9 * x^^2 + 2 * x^^3;
alias df = (x) => 4.5 + 2 * 1.9 * x^^1 + 3 * 2 * x^^2;
alias d2f = (x) => 2 * 1.9  + 6 * 2 * x^^1;

assert(p(3.3).approxEqual(f(3.3)));
assert(p(7.2).approxEqual(f(7.2)));

assert(p.opCall!1(3.3).approxEqual(df(3.3)));
assert(p.opCall!1(7.2).approxEqual(df(7.2)));

assert(p.opCall!2(3.3).approxEqual(d2f(3.3)));
assert(p.opCall!2(7.2).approxEqual(d2f(7.2)));

Meta