nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
Polynomials and Interpolation (polyfun)

Polynomial curve fitting, roots, derivatives, integration, 1D/2D/3D interpolation, and piecewise cubic splines. More...

Files

file  polyfun.hpp

Classes

struct  nk::builtin::PolyDiv
 Result of polynomial division and deconvolution ([q, r] = polydiv(b, a)). More...
struct  nk::builtin::PadeCoef
 Padé approximation numerator and denominator polynomials. More...
struct  nk::builtin::ResidueResult
 Result of partial fraction expansion (residues, poles, direct term). More...
struct  nk::builtin::MatchpairsResult
 Result of linear assignment problem (matchpairs). More...
struct  nk::builtin::InpolygonResult
 Result of 2-D polygon inclusion test (inpolygon). More...
struct  nk::builtin::PolyxpolyResult
 Result of polygon intersection (polyxpoly). More...

Functions

Value nk::builtin::roots (const Value &p, std::pmr::memory_resource *mr=nullptr)
 Computes polynomial roots (roots(p)).
Value nk::builtin::poly (const Value &r, std::pmr::memory_resource *mr=nullptr)
 Polynomial with specified roots or characteristic polynomial of a matrix.
Value nk::builtin::polyval (const Value &p, const Value &x, std::pmr::memory_resource *mr=nullptr)
 Evaluates polynomial p at points x via Horner's scheme.
Value nk::builtin::polyder (const Value &p, std::pmr::memory_resource *mr=nullptr)
 Computes polynomial derivative (polyder(p)).
std::tuple< Value, Value > nk::builtin::polyder (const Value &b, const Value &a, std::pmr::memory_resource *mr=nullptr)
 Computes derivative of polynomial quotient b / a ([q, d] = polyder(b, a)).
Value nk::builtin::polyint (const Value &p, double k=0.0, std::pmr::memory_resource *mr=nullptr)
 Computes polynomial integral (polyint(p, k)).
Value nk::builtin::polyfit (const Value &x, const Value &y, int n, std::pmr::memory_resource *mr=nullptr)
 Polynomial least-squares curve fitting (polyfit(x, y, n)).
Value nk::builtin::polyvalm (const Value &p, const Value &A, std::pmr::memory_resource *mr=nullptr)
 Matrix polynomial evaluation (polyvalm(p, A)).
Value nk::builtin::poly_of_matrix (const Value &A, std::pmr::memory_resource *mr=nullptr)
 Characteristic polynomial of square matrix (poly_of_matrix(A)).
PadeCoef nk::builtin::padecoef (double T, int N, std::pmr::memory_resource *mr=nullptr)
 Padé approximation of time delay ([num, den] = padecoef(T, N)).
PolyDiv nk::builtin::polydiv (const Value &b, const Value &a, std::pmr::memory_resource *mr=nullptr)
 Polynomial deconvolution and division ([q, r] = polydiv(b, a)).
std::tuple< Value, Value, Value > nk::builtin::tf2zp (const Value &b, const Value &a, std::pmr::memory_resource *mr=nullptr)
 Transfer function to zero-pole-gain conversion ([z, p, k] = tf2zp(b, a)).
std::tuple< Value, Value > nk::builtin::zp2tf (const Value &z, const Value &p, double k, std::pmr::memory_resource *mr=nullptr)
 Zero-pole-gain to transfer function conversion ([b, a] = zp2tf(z, p, k)).
ResidueResult nk::builtin::residue (const Value &b, const Value &a, std::pmr::memory_resource *mr=nullptr)
 Partial fraction expansion (residues) in Laplace s-domain ([r, p, k] = residue(b, a)).
ResidueResult nk::builtin::residuez (const Value &b, const Value &a, std::pmr::memory_resource *mr=nullptr)
 Partial fraction expansion in Z-domain ([r, p, k] = residuez(b, a)).
Value nk::builtin::interp1 (const Value &x, const Value &v, const Value &xq, const std::string &method="linear", std::pmr::memory_resource *mr=nullptr)
 1-D table lookup and data interpolation (interp1(x, v, xq, method)).
Value nk::builtin::interp2 (const Value &V, const Value &Xq, const Value &Yq, const std::string &method="linear", std::pmr::memory_resource *mr=nullptr)
 2-D data interpolation on a grid (interp2(x, y, v, xq, yq, method)).
Value nk::builtin::interp2 (const Value &x, const Value &y, const Value &v, const Value &xq, const Value &yq, const std::string &method="linear", std::pmr::memory_resource *mr=nullptr)
 2-D data interpolation on a grid (interp2(x, y, v, xq, yq, method)).
Value nk::builtin::interp3 (const Value &V, const Value &Xq, const Value &Yq, const Value &Zq, const std::string &method="linear", std::pmr::memory_resource *mr=nullptr)
 3-D data interpolation on a uniform grid (interp3(V, Xq, Yq, Zq, method)).
Value nk::builtin::interp3 (const Value &X, const Value &Y, const Value &Z, const Value &V, const Value &Xq, const Value &Yq, const Value &Zq, const std::string &method="linear", std::pmr::memory_resource *mr=nullptr)
 3-D data interpolation on a grid (interp3(X, Y, Z, V, Xq, Yq, Zq, method)).
Value nk::builtin::spline (const Value &x, const Value &y, const Value &xq=Value(), std::pmr::memory_resource *mr=nullptr)
 Cubic spline data interpolation (spline(x, y, xq)).
Value nk::builtin::pchip (const Value &x, const Value &y, const Value &xq=Value(), std::pmr::memory_resource *mr=nullptr)
 Piecewise Cubic Hermite Interpolating Polynomial (PCHIP) (pchip(x, y, xq)).
Value nk::builtin::makima (const Value &x, const Value &y, const Value &xq, std::pmr::memory_resource *mr=nullptr)
 Modified Akima cubic Hermite interpolation (makima(x, y, xq)).
Value nk::builtin::mkpp (const Value &breaks, const Value &coefs, std::pmr::memory_resource *mr=nullptr)
 Constructs a piecewise polynomial structure (ppform).
Value nk::builtin::unmkpp (const Value &pp, std::pmr::memory_resource *mr=nullptr)
 Extracts piecewise polynomial structure fields ([breaks, coefs, l, k, d] = unmkpp(pp)).
Value nk::builtin::ppval (const Value &pp, const Value &xq, std::pmr::memory_resource *mr=nullptr)
 Evaluates a piecewise polynomial structure at query points xq.
Value nk::builtin::gradient (const Value &f, double h=1.0, std::pmr::memory_resource *mr=nullptr)
 Numerical gradient of 1-D array or uniform multi-dimensional array (gradient(f, h)).
std::tuple< Value, Value > nk::builtin::gradient2 (const Value &f, double hx=1.0, double hy=1.0, std::pmr::memory_resource *mr=nullptr)
 Numerical 2-D gradient along rows and columns ([fx, fy] = gradient(f, hx, hy)).
Value nk::builtin::del2 (const Value &u, double h=1.0, std::pmr::memory_resource *mr=nullptr)
 Five-point discrete Laplacian / Laplace operator (del2(u, h)).
Value nk::builtin::trapz (const Value &y, std::pmr::memory_resource *mr=nullptr)
 Trapezoidal numerical integration with unit spacing (trapz(y)).
Value nk::builtin::trapz (const Value &x, const Value &y, std::pmr::memory_resource *mr=nullptr)
 Trapezoidal numerical integration over coordinates x (trapz(x, y)).
Value nk::builtin::trapz (const Value &x, const Value &y, int dim, std::pmr::memory_resource *mr=nullptr)
 Trapezoidal numerical integration along specified dimension (trapz(x, y, dim)).
Value nk::builtin::cumtrapz (const Value &y, std::pmr::memory_resource *mr=nullptr)
 Cumulative trapezoidal numerical integration with unit spacing (cumtrapz(y)).
Value nk::builtin::cumtrapz (const Value &x, const Value &y, std::pmr::memory_resource *mr=nullptr)
 Cumulative trapezoidal numerical integration over coordinates x (cumtrapz(x, y)).
Value nk::builtin::cumtrapz (const Value &x, const Value &y, int dim, std::pmr::memory_resource *mr=nullptr)
 Cumulative trapezoidal numerical integration along dimension (cumtrapz(x, y, dim)).
Value nk::builtin::cumtrapzDim (const Value &y, int dim, std::pmr::memory_resource *mr=nullptr)
 Cumulative trapezoidal numerical integration with unit spacing along dimension (cumtrapz(y, dim)).
Value nk::builtin::integral (FnHandle fn, double a, double b, double absTol=1e-10, std::pmr::memory_resource *mr=nullptr)
 Numerical 1-D adaptive quadrature integration (integral(fn, a, b)).
Value nk::builtin::integral2 (FnHandle fn, double a, double b, double c, double d, double absTol=1e-10, std::pmr::memory_resource *mr=nullptr)
 Numerical 2-D double integration over rectangular region (integral2(fn, a, b, c, d)).
Value nk::builtin::integral3 (FnHandle fn, double a, double b, double c, double d, double e, double f, double absTol=1e-10, std::pmr::memory_resource *mr=nullptr)
 Numerical 3-D triple integration over cuboid region (integral3(fn, a, b, c, d, e, f)).
Value nk::builtin::polyarea (const Value &x, const Value &y, std::pmr::memory_resource *mr=nullptr)
 Area of 2-D polygonal contour (polyarea(x, y)).
Value nk::builtin::inpolygon (const Value &xq, const Value &yq, const Value &xv, const Value &yv, std::pmr::memory_resource *mr=nullptr)
 Tests if 2-D query points are inside polygonal region (inpolygon(xq, yq, xv, yv)).
InpolygonResult nk::builtin::inpolygon2 (const Value &xq, const Value &yq, const Value &xv, const Value &yv, std::pmr::memory_resource *mr=nullptr)
 Tests points inside and on edge of 2-D polygonal region ([in, on] = inpolygon(xq, yq, xv, yv)).
Value nk::builtin::convhull (const Value &x, const Value &y, std::pmr::memory_resource *mr=nullptr)
 Computes 2-D convex hull of planar point set (convhull(x, y)).
PolyxpolyResult nk::builtin::polyxpoly (const Value &x1, const Value &y1, const Value &x2, const Value &y2, std::pmr::memory_resource *mr=nullptr)
 Intersection points of polygonal lines or boundaries ([xi, yi] = polyxpoly(x1, y1, x2, y2)).
MatchpairsResult nk::builtin::matchpairs (const Value &C, double cU, const std::string &mode="min", std::pmr::memory_resource *mr=nullptr)
 Solves linear sum assignment problem with cost threshold (matchpairs(C, cU, mode)).
Value nk::builtin::boundary (const Value &x, const Value &y, double shrink=0.5, std::pmr::memory_resource *mr=nullptr)
 Computes boundary / alpha-shape around 2-D point cloud (boundary(x, y, shrink)).
Value nk::builtin::delaunay (const Value &x, const Value &y, std::pmr::memory_resource *mr=nullptr)
 2-D Delaunay triangulation of planar point set (delaunay(x, y)).
Value nk::builtin::griddata (const Value &x, const Value &y, const Value &v, const Value &xq, const Value &yq, std::pmr::memory_resource *mr=nullptr)
 Interpolates scattered 2-D data onto query points (griddata(x, y, v, xq, yq, method)).
Value nk::builtin::griddata (const Value &x, const Value &y, const Value &v, const Value &xq, const Value &yq, const std::string &method, std::pmr::memory_resource *mr=nullptr)
 Interpolates scattered 2-D data onto query points with specified method (griddata(x, y, v, xq, yq, method)).
Value nk::builtin::griddatan (const Value &Xv, const Value &vv, const Value &xi, std::pmr::memory_resource *mr=nullptr)
 N-D scattered data interpolation (griddatan(Xv, vv, xi, method)).
Value nk::builtin::griddatan (const Value &Xv, const Value &vv, const Value &xi, const std::string &method, std::pmr::memory_resource *mr=nullptr)
 N-D scattered data interpolation with method (griddatan(Xv, vv, xi, method)).
Value nk::builtin::histcounts2 (const Value &x, const Value &y, const Value &xedgesV, const Value &yedgesV, std::pmr::memory_resource *mr=nullptr)
 Computes 2-D bivariate histogram bin counts (histcounts2(x, y, xedges, yedges)).

Detailed Description

Polynomial curve fitting, roots, derivatives, integration, 1D/2D/3D interpolation, and piecewise cubic splines.

Function Documentation

◆ boundary()

Value nk::builtin::boundary ( const Value & x,
const Value & y,
double shrink = 0.5,
std::pmr::memory_resource * mr = nullptr )

Computes boundary / alpha-shape around 2-D point cloud (boundary(x, y, shrink)).

Parameters
xPoint x-coordinates.
yPoint y-coordinates.
shrinkShrink factor between 0.0 (convex hull) and 1.0 (compact boundary).
mrMemory resource.
Returns
Indices of boundary points.
See also
convhull

◆ convhull()

Value nk::builtin::convhull ( const Value & x,
const Value & y,
std::pmr::memory_resource * mr = nullptr )

Computes 2-D convex hull of planar point set (convhull(x, y)).

Parameters
xPoint x-coordinates.
yPoint y-coordinates.
mrMemory resource.
Returns
Indices of vertices forming the convex hull in counterclockwise order.
See also
delaunay, boundary

◆ cumtrapz() [1/3]

Value nk::builtin::cumtrapz ( const Value & x,
const Value & y,
int dim,
std::pmr::memory_resource * mr = nullptr )

Cumulative trapezoidal numerical integration along dimension (cumtrapz(x, y, dim)).

Parameters
xCoordinate points.
yFunction values.
dimOperating dimension.
mrMemory resource.
Returns
Cumulative integral array.

◆ cumtrapz() [2/3]

Value nk::builtin::cumtrapz ( const Value & x,
const Value & y,
std::pmr::memory_resource * mr = nullptr )

Cumulative trapezoidal numerical integration over coordinates x (cumtrapz(x, y)).

Parameters
xCoordinate points.
yFunction values.
mrMemory resource.
Returns
Cumulative integral array.

◆ cumtrapz() [3/3]

Value nk::builtin::cumtrapz ( const Value & y,
std::pmr::memory_resource * mr = nullptr )

Cumulative trapezoidal numerical integration with unit spacing (cumtrapz(y)).

Parameters
yFunction values.
mrMemory resource.
Returns
Cumulative integral array.
See also
trapz

◆ cumtrapzDim()

Value nk::builtin::cumtrapzDim ( const Value & y,
int dim,
std::pmr::memory_resource * mr = nullptr )

Cumulative trapezoidal numerical integration with unit spacing along dimension (cumtrapz(y, dim)).

Parameters
yFunction values.
dimOperating dimension.
mrMemory resource.
Returns
Cumulative integral array.

◆ del2()

Value nk::builtin::del2 ( const Value & u,
double h = 1.0,
std::pmr::memory_resource * mr = nullptr )

Five-point discrete Laplacian / Laplace operator (del2(u, h)).

Parameters
uInput array.
hSpacing between grid points (default 1.0).
mrMemory resource.
Returns
Discrete Laplacian array.
See also
gradient

◆ delaunay()

Value nk::builtin::delaunay ( const Value & x,
const Value & y,
std::pmr::memory_resource * mr = nullptr )

2-D Delaunay triangulation of planar point set (delaunay(x, y)).

Parameters
xPoint x-coordinates.
yPoint y-coordinates.
mrMemory resource.
Returns
M x 3 matrix where each row defines a triangle by point indices.
See also
convhull

◆ gradient()

Value nk::builtin::gradient ( const Value & f,
double h = 1.0,
std::pmr::memory_resource * mr = nullptr )

Numerical gradient of 1-D array or uniform multi-dimensional array (gradient(f, h)).

Parameters
fInput array.
hGrid step size (default 1.0).
mrMemory resource.
Returns
Approximate derivative along the operating dimension.
See also
del2, diff

◆ gradient2()

std::tuple< Value, Value > nk::builtin::gradient2 ( const Value & f,
double hx = 1.0,
double hy = 1.0,
std::pmr::memory_resource * mr = nullptr )

Numerical 2-D gradient along rows and columns ([fx, fy] = gradient(f, hx, hy)).

Parameters
f2-D input matrix.
hxGrid spacing along X.
hyGrid spacing along Y.
mrMemory resource.
Returns
Tuple containing {fx, fy} partial derivatives.

◆ griddata() [1/2]

Value nk::builtin::griddata ( const Value & x,
const Value & y,
const Value & v,
const Value & xq,
const Value & yq,
const std::string & method,
std::pmr::memory_resource * mr = nullptr )

Interpolates scattered 2-D data onto query points with specified method (griddata(x, y, v, xq, yq, method)).

Parameters
xScattered point x-coordinates.
yScattered point y-coordinates.
vSample values at scattered points.
xqQuery point x-coordinates.
yqQuery point y-coordinates.
methodInterpolation method ("linear", "nearest", "cubic", "natural").
mrMemory resource.
Returns
Interpolated surface values.

◆ griddata() [2/2]

Value nk::builtin::griddata ( const Value & x,
const Value & y,
const Value & v,
const Value & xq,
const Value & yq,
std::pmr::memory_resource * mr = nullptr )

Interpolates scattered 2-D data onto query points (griddata(x, y, v, xq, yq, method)).

Parameters
xScattered point x-coordinates.
yScattered point y-coordinates.
vSample values at scattered points.
xqQuery point x-coordinates.
yqQuery point y-coordinates.
mrMemory resource.
Returns
Interpolated surface values.
See also
griddatan, interp2

◆ griddatan() [1/2]

Value nk::builtin::griddatan ( const Value & Xv,
const Value & vv,
const Value & xi,
const std::string & method,
std::pmr::memory_resource * mr = nullptr )

N-D scattered data interpolation with method (griddatan(Xv, vv, xi, method)).

Parameters
XvM x N sample point coordinates.
vvSample values.
xiQuery point coordinates.
methodInterpolation method ("linear", "nearest").
mrMemory resource.
Returns
Interpolated values.

◆ griddatan() [2/2]

Value nk::builtin::griddatan ( const Value & Xv,
const Value & vv,
const Value & xi,
std::pmr::memory_resource * mr = nullptr )

N-D scattered data interpolation (griddatan(Xv, vv, xi, method)).

Parameters
XvM x N matrix of scattered sample point coordinates.
vvM x 1 sample values.
xiP x N matrix of query point coordinates.
mrMemory resource.
Returns
Interpolated values vector P x 1.
See also
griddata

◆ histcounts2()

Value nk::builtin::histcounts2 ( const Value & x,
const Value & y,
const Value & xedgesV,
const Value & yedgesV,
std::pmr::memory_resource * mr = nullptr )

Computes 2-D bivariate histogram bin counts (histcounts2(x, y, xedges, yedges)).

Parameters
xData points x-coordinates.
yData points y-coordinates.
xedgesVBin edges vector along X.
yedgesVBin edges vector along Y.
mrMemory resource.
Returns
2-D matrix of bivariate count values.

◆ inpolygon()

Value nk::builtin::inpolygon ( const Value & xq,
const Value & yq,
const Value & xv,
const Value & yv,
std::pmr::memory_resource * mr = nullptr )

Tests if 2-D query points are inside polygonal region (inpolygon(xq, yq, xv, yv)).

Parameters
xqQuery points x-coordinates.
yqQuery points y-coordinates.
xvPolygon vertices x-coordinates.
yvPolygon vertices y-coordinates.
mrMemory resource.
Returns
Logical array indicating whether query points lie inside or on edge.
See also
inpolygon2

◆ inpolygon2()

InpolygonResult nk::builtin::inpolygon2 ( const Value & xq,
const Value & yq,
const Value & xv,
const Value & yv,
std::pmr::memory_resource * mr = nullptr )

Tests points inside and on edge of 2-D polygonal region ([in, on] = inpolygon(xq, yq, xv, yv)).

Parameters
xqQuery points x-coordinates.
yqQuery points y-coordinates.
xvPolygon vertices x-coordinates.
yvPolygon vertices y-coordinates.
mrMemory resource.
Returns
Struct containing {in, on} logical arrays.

◆ integral()

Value nk::builtin::integral ( FnHandle fn,
double a,
double b,
double absTol = 1e-10,
std::pmr::memory_resource * mr = nullptr )

Numerical 1-D adaptive quadrature integration (integral(fn, a, b)).

Parameters
fnFunction handle taking numeric vector argument.
aLower integration limit.
bUpper integration limit.
absTolAbsolute error tolerance.
mrMemory resource.
Returns
Integral value.
See also
integral2, integral3, trapz

◆ integral2()

Value nk::builtin::integral2 ( FnHandle fn,
double a,
double b,
double c,
double d,
double absTol = 1e-10,
std::pmr::memory_resource * mr = nullptr )

Numerical 2-D double integration over rectangular region (integral2(fn, a, b, c, d)).

Parameters
fnFunction handle taking (x, y).
aLower limit in x.
bUpper limit in x.
cLower limit in y.
dUpper limit in y.
absTolAbsolute error tolerance.
mrMemory resource.
Returns
Double integral value.
See also
integral, integral3

◆ integral3()

Value nk::builtin::integral3 ( FnHandle fn,
double a,
double b,
double c,
double d,
double e,
double f,
double absTol = 1e-10,
std::pmr::memory_resource * mr = nullptr )

Numerical 3-D triple integration over cuboid region (integral3(fn, a, b, c, d, e, f)).

Parameters
fnFunction handle taking (x, y, z).
aLower limit in x.
bUpper limit in x.
cLower limit in y.
dUpper limit in y.
eLower limit in z.
fUpper limit in z.
absTolAbsolute error tolerance.
mrMemory resource.
Returns
Triple integral value.
See also
integral, integral2

◆ interp1()

Value nk::builtin::interp1 ( const Value & x,
const Value & v,
const Value & xq,
const std::string & method = "linear",
std::pmr::memory_resource * mr = nullptr )

1-D table lookup and data interpolation (interp1(x, v, xq, method)).

Parameters
xSample grid points (strictly monotonic).
vSample values.
xqQuery points.
methodInterpolation method: "linear", "nearest", "next", "previous", "spline", "pchip".
mrMemory resource.
Returns
Interpolated values at query points xq.
See also
interp2, spline, pchip

◆ interp2() [1/2]

Value nk::builtin::interp2 ( const Value & V,
const Value & Xq,
const Value & Yq,
const std::string & method = "linear",
std::pmr::memory_resource * mr = nullptr )

2-D data interpolation on a grid (interp2(x, y, v, xq, yq, method)).

Parameters
xGrid coordinates along columns.
yGrid coordinates along rows.
vMatrix of values on grid.
xqQuery points x-coordinates.
yqQuery points y-coordinates.
methodInterpolation method: "linear", "nearest", "cubic", "spline".
mrMemory resource.
Returns
Interpolated values.
See also
interp1

2-D data interpolation on a uniform grid (interp2(V, Xq, Yq, method)).

Parameters
VMatrix of values on default integer grid.
XqQuery points x-coordinates.
YqQuery points y-coordinates.
methodInterpolation method ("linear", "nearest", "cubic", "spline").
mrMemory resource.
Returns
Interpolated values.

◆ interp2() [2/2]

Value nk::builtin::interp2 ( const Value & x,
const Value & y,
const Value & v,
const Value & xq,
const Value & yq,
const std::string & method = "linear",
std::pmr::memory_resource * mr = nullptr )

2-D data interpolation on a grid (interp2(x, y, v, xq, yq, method)).

Parameters
xGrid coordinates along columns.
yGrid coordinates along rows.
vMatrix of values on grid.
xqQuery points x-coordinates.
yqQuery points y-coordinates.
methodInterpolation method: "linear", "nearest", "cubic", "spline".
mrMemory resource.
Returns
Interpolated values.
See also
interp1

◆ interp3() [1/2]

Value nk::builtin::interp3 ( const Value & V,
const Value & Xq,
const Value & Yq,
const Value & Zq,
const std::string & method = "linear",
std::pmr::memory_resource * mr = nullptr )

3-D data interpolation on a uniform grid (interp3(V, Xq, Yq, Zq, method)).

Parameters
V3-D array of values.
XqQuery points x-coordinates.
YqQuery points y-coordinates.
ZqQuery points z-coordinates.
methodInterpolation method.
mrMemory resource.
Returns
Interpolated 3-D array.

◆ interp3() [2/2]

Value nk::builtin::interp3 ( const Value & X,
const Value & Y,
const Value & Z,
const Value & V,
const Value & Xq,
const Value & Yq,
const Value & Zq,
const std::string & method = "linear",
std::pmr::memory_resource * mr = nullptr )

3-D data interpolation on a grid (interp3(X, Y, Z, V, Xq, Yq, Zq, method)).

Parameters
XGrid coordinates along X.
YGrid coordinates along Y.
ZGrid coordinates along Z.
V3-D array of values.
XqQuery points x-coordinates.
YqQuery points y-coordinates.
ZqQuery points z-coordinates.
methodInterpolation method.
mrMemory resource.
Returns
Interpolated 3-D array.

◆ makima()

Value nk::builtin::makima ( const Value & x,
const Value & y,
const Value & xq,
std::pmr::memory_resource * mr = nullptr )

Modified Akima cubic Hermite interpolation (makima(x, y, xq)).

Parameters
xSample grid points.
ySample values.
xqQuery points.
mrMemory resource.
Returns
Interpolated values with reduced overshoots.
See also
spline, pchip

◆ matchpairs()

MatchpairsResult nk::builtin::matchpairs ( const Value & C,
double cU,
const std::string & mode = "min",
std::pmr::memory_resource * mr = nullptr )

Solves linear sum assignment problem with cost threshold (matchpairs(C, cU, mode)).

Parameters
CCost matrix.
cUUnmatched cost threshold.
modeOptimization mode ("min" or "max").
mrMemory resource.
Returns
Matchpairs result containing matched indices and unmatched rows/cols.

◆ mkpp()

Value nk::builtin::mkpp ( const Value & breaks,
const Value & coefs,
std::pmr::memory_resource * mr = nullptr )

Constructs a piecewise polynomial structure (ppform).

Parameters
breaksVector of break points.
coefsMatrix of local polynomial coefficients.
mrMemory resource.
Returns
Piecewise polynomial struct.
See also
unmkpp, ppval

◆ padecoef()

PadeCoef nk::builtin::padecoef ( double T,
int N,
std::pmr::memory_resource * mr = nullptr )

Padé approximation of time delay ([num, den] = padecoef(T, N)).

Computes order-N Padé rational approximation of time delay exp(-s*T).

Parameters
TTime delay in seconds.
NApproximation order.
mrMemory resource for allocations (nullptr for default).
Returns
PadeCoef containing numerator and denominator polynomials.

◆ pchip()

Value nk::builtin::pchip ( const Value & x,
const Value & y,
const Value & xq = Value(),
std::pmr::memory_resource * mr = nullptr )

Piecewise Cubic Hermite Interpolating Polynomial (PCHIP) (pchip(x, y, xq)).

Parameters
xSample grid points.
ySample values.
xqQuery points (or empty to return piecewise polynomial structure).
mrMemory resource.
Returns
Shape-preserving interpolated values or piecewise polynomial struct.
See also
spline, makima, ppval

◆ poly()

Value nk::builtin::poly ( const Value & r,
std::pmr::memory_resource * mr = nullptr )

Polynomial with specified roots or characteristic polynomial of a matrix.

Parameters
rVector of roots or square matrix.
mrMemory resource.
Returns
Row vector of polynomial coefficients in descending powers.
See also
roots, polyval

◆ poly_of_matrix()

Value nk::builtin::poly_of_matrix ( const Value & A,
std::pmr::memory_resource * mr = nullptr )

Characteristic polynomial of square matrix (poly_of_matrix(A)).

Computes coefficients of det(s*I - A).

Parameters
ASquare matrix.
mrMemory resource for allocations (nullptr for default).
Returns
Row vector containing characteristic polynomial coefficients.
See also
poly, roots, polyvalm

◆ polyarea()

Value nk::builtin::polyarea ( const Value & x,
const Value & y,
std::pmr::memory_resource * mr = nullptr )

Area of 2-D polygonal contour (polyarea(x, y)).

Parameters
xVertex x-coordinates.
yVertex y-coordinates.
mrMemory resource.
Returns
Signed or unsigned polygon area.

◆ polyder() [1/2]

std::tuple< Value, Value > nk::builtin::polyder ( const Value & b,
const Value & a,
std::pmr::memory_resource * mr = nullptr )

Computes derivative of polynomial quotient b / a ([q, d] = polyder(b, a)).

Parameters
bNumerator polynomial coefficients.
aDenominator polynomial coefficients.
mrMemory resource.
Returns
Tuple containing numerator and denominator polynomial coefficients {q, d}.

◆ polyder() [2/2]

Value nk::builtin::polyder ( const Value & p,
std::pmr::memory_resource * mr = nullptr )

Computes polynomial derivative (polyder(p)).

Parameters
pVector of polynomial coefficients.
mrMemory resource.
Returns
Derivative polynomial coefficients.
See also
polyint, polyval

◆ polydiv()

PolyDiv nk::builtin::polydiv ( const Value & b,
const Value & a,
std::pmr::memory_resource * mr = nullptr )

Polynomial deconvolution and division ([q, r] = polydiv(b, a)).

Parameters
bDividend polynomial coefficients.
aDivisor polynomial coefficients.
mrMemory resource for allocations (nullptr for default).
Returns
PolyDiv containing quotient q and remainder r.
See also
deconv, conv

◆ polyfit()

Value nk::builtin::polyfit ( const Value & x,
const Value & y,
int n,
std::pmr::memory_resource * mr = nullptr )

Polynomial least-squares curve fitting (polyfit(x, y, n)).

Parameters
xIndependent variable vector.
yDependent variable vector.
nDegree of the fitting polynomial.
mrMemory resource.
Returns
Fitted polynomial coefficients of length n + 1.

◆ polyint()

Value nk::builtin::polyint ( const Value & p,
double k = 0.0,
std::pmr::memory_resource * mr = nullptr )

Computes polynomial integral (polyint(p, k)).

Parameters
pVector of polynomial coefficients.
kConstant of integration (default: 0.0).
mrMemory resource.
Returns
Integrated polynomial coefficients.
See also
polyder, polyval

◆ polyval()

Value nk::builtin::polyval ( const Value & p,
const Value & x,
std::pmr::memory_resource * mr = nullptr )

Evaluates polynomial p at points x via Horner's scheme.

Parameters
pVector of polynomial coefficients.
xEvaluation point(s).
mrMemory resource.
Returns
Evaluated values with the same shape as x.
See also
roots, polyder, polyint

◆ polyvalm()

Value nk::builtin::polyvalm ( const Value & p,
const Value & A,
std::pmr::memory_resource * mr = nullptr )

Matrix polynomial evaluation (polyvalm(p, A)).

Evaluates polynomial p at square matrix A using Horner's method with matrix multiplications: Y = p[0]*A^n + p[1]*A^(n-1) + ... + p[n]*I.

Parameters
pCoefficient vector in descending powers of s.
ASquare matrix.
mrMemory resource for allocations (nullptr for default).
Returns
Square matrix result of polynomial evaluation.
See also
polyval, poly_of_matrix

◆ polyxpoly()

PolyxpolyResult nk::builtin::polyxpoly ( const Value & x1,
const Value & y1,
const Value & x2,
const Value & y2,
std::pmr::memory_resource * mr = nullptr )

Intersection points of polygonal lines or boundaries ([xi, yi] = polyxpoly(x1, y1, x2, y2)).

Parameters
x1First line x-coordinates.
y1First line y-coordinates.
x2Second line x-coordinates.
y2Second line y-coordinates.
mrMemory resource.
Returns
Intersection coordinates struct.

◆ ppval()

Value nk::builtin::ppval ( const Value & pp,
const Value & xq,
std::pmr::memory_resource * mr = nullptr )

Evaluates a piecewise polynomial structure at query points xq.

Parameters
ppPiecewise polynomial structure.
xqQuery points.
mrMemory resource.
Returns
Evaluated values.
See also
mkpp, unmkpp, spline, pchip

◆ residue()

ResidueResult nk::builtin::residue ( const Value & b,
const Value & a,
std::pmr::memory_resource * mr = nullptr )

Partial fraction expansion (residues) in Laplace s-domain ([r, p, k] = residue(b, a)).

Converts transfer function B(s)/A(s) to partial fraction form: B(s)/A(s) = r(1)/(s-p(1)) + ... + r(n)/(s-p(n)) + k(s).

Parameters
bNumerator polynomial coefficients in descending powers of s.
aDenominator polynomial coefficients in descending powers of s.
mrMemory resource for allocations (nullptr for default).
Returns
ResidueResult containing residues r, poles p, and direct terms k.
See also
residuez, poly, roots

◆ residuez()

ResidueResult nk::builtin::residuez ( const Value & b,
const Value & a,
std::pmr::memory_resource * mr = nullptr )

Partial fraction expansion in Z-domain ([r, p, k] = residuez(b, a)).

Converts discrete transfer function B(z)/A(z) to partial fraction form in z^-1: B(z)/A(z) = r(1)/(1 - p(1)*z^-1) + ... + k(z^-1).

Parameters
bNumerator polynomial coefficients in descending powers of z.
aDenominator polynomial coefficients in descending powers of z.
mrMemory resource for allocations (nullptr for default).
Returns
ResidueResult containing residues r, poles p, and direct terms k.
See also
residue, poly, roots

◆ roots()

Value nk::builtin::roots ( const Value & p,
std::pmr::memory_resource * mr = nullptr )

Computes polynomial roots (roots(p)).

Parameters
pVector of polynomial coefficients in descending powers: p[0]*x^N + ... + p[N].
mrMemory resource for allocations (nullptr for default).
Returns
Column vector of complex/real roots (eigenvalues of companion matrix).
See also
poly, polyval

◆ spline()

Value nk::builtin::spline ( const Value & x,
const Value & y,
const Value & xq = Value(),
std::pmr::memory_resource * mr = nullptr )

Cubic spline data interpolation (spline(x, y, xq)).

Parameters
xSample grid points.
ySample values.
xqQuery points (or empty to return piecewise polynomial structure).
mrMemory resource.
Returns
Interpolated values or piecewise polynomial struct.
See also
pchip, makima, ppval

◆ tf2zp()

std::tuple< Value, Value, Value > nk::builtin::tf2zp ( const Value & b,
const Value & a,
std::pmr::memory_resource * mr = nullptr )

Transfer function to zero-pole-gain conversion ([z, p, k] = tf2zp(b, a)).

Parameters
bNumerator polynomial coefficients.
aDenominator polynomial coefficients.
mrMemory resource for allocations (nullptr for default).
Returns
Tuple containing zeros z, poles p, and gain k.
See also
zp2tf, residue

◆ trapz() [1/3]

Value nk::builtin::trapz ( const Value & x,
const Value & y,
int dim,
std::pmr::memory_resource * mr = nullptr )

Trapezoidal numerical integration along specified dimension (trapz(x, y, dim)).

Parameters
xCoordinate points.
yFunction values.
dimDimension along which to integrate.
mrMemory resource.
Returns
Integrated array.

◆ trapz() [2/3]

Value nk::builtin::trapz ( const Value & x,
const Value & y,
std::pmr::memory_resource * mr = nullptr )

Trapezoidal numerical integration over coordinates x (trapz(x, y)).

Parameters
xCoordinate points.
yFunction values.
mrMemory resource.
Returns
Integral approximation.
See also
cumtrapz, integral

◆ trapz() [3/3]

Value nk::builtin::trapz ( const Value & y,
std::pmr::memory_resource * mr = nullptr )

Trapezoidal numerical integration with unit spacing (trapz(y)).

Parameters
yFunction values vector or array.
mrMemory resource.
Returns
Integral approximation.
See also
cumtrapz, integral

◆ unmkpp()

Value nk::builtin::unmkpp ( const Value & pp,
std::pmr::memory_resource * mr = nullptr )

Extracts piecewise polynomial structure fields ([breaks, coefs, l, k, d] = unmkpp(pp)).

Parameters
ppPiecewise polynomial struct.
mrMemory resource.
Returns
Breaks vector from pp struct.
See also
mkpp, ppval

◆ zp2tf()

std::tuple< Value, Value > nk::builtin::zp2tf ( const Value & z,
const Value & p,
double k,
std::pmr::memory_resource * mr = nullptr )

Zero-pole-gain to transfer function conversion ([b, a] = zp2tf(z, p, k)).

Parameters
zZeros vector.
pPoles vector.
kScalar gain factor.
mrMemory resource for allocations (nullptr for default).
Returns
Tuple containing numerator b and denominator a polynomials.
See also
tf2zp, residue