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.polynomial

Polynomial ref-counted structure.
License:
Authors:
Ilya Yaroshenko
struct Polynomial(F);

Polynomial!F polynomial(F)(RCArray!(const(F)) coefficients);
Polynomial callable ref-counted structure.
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)));
RCArray!(const(F)) coefficients;
this(RCArray!(const(F)) coefficients);
Parameters:
RCArray!(const(F)) coefficients coefficients c[i] for polynomial function f(x)=c[0]+c[1]*x^^1+...+c[n]*x^^n
template opCall(uint derivative = 0)
Parameters:
derivative derivative order
const typeof(F.init * X.init * 1.0F + F.init) opCall(X)(in X x);
Parameters:
X x x point