7 #include "cantera/numerics/eigen_dense.h" 14 double polyfit(
int n,
double* xp,
double* yp,
double* wp,
15 int deg,
int& ndeg,
double eps,
double* rp)
18 "The ndeg and eps arguments to polyfit are deprecated and unused. Use " 19 "the form of polyfit with signature polyfit(n, deg, x, y, w, p). To be " 20 "removed after Cantera 2.3.");
22 return polyfit(n, deg, xp, yp, wp, rp);
25 double polyfit(
size_t n,
size_t deg,
const double* xp,
const double* yp,
26 const double* wp,
double* pp)
28 ConstMappedVector x(xp, n);
29 Eigen::VectorXd y = ConstMappedVector(yp, n);
30 MappedVector p(pp, deg+1);
33 throw CanteraError(
"polyfit",
"Polynomial degree ({}) must be less " 34 "than number of input data points ({})", deg, n);
39 Eigen::MatrixXd A(n, deg+1);
40 A.col(0).setConstant(1.0);
45 for (
size_t i = 1; i < deg; i++) {
46 A.col(i+1) = A.col(i).array() * x.array();
49 if (wp !=
nullptr && wp[0] > 0) {
52 Eigen::VectorXd w = ConstMappedVector(wp, n).cwiseSqrt().eval();
55 A = w.asDiagonal() * A;
56 y.array() *= w.array();
60 p = A.colPivHouseholderQr().solve(y);
64 return (A*p - y).eval().norm() / sqrt(n);
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, (see Input File Handling, Diagnostic Output, and Writing messages to the screen).
double polyfit(int n, double *xp, double *yp, double *wp, int deg, int &ndeg, double eps, double *rp)
Fits a polynomial function to a set of data points.
Base class for exceptions thrown by Cantera classes.
Namespace for the Cantera kernel.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...