mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
42 lines
931 B
C++
42 lines
931 B
C++
#include "quartic_model.h"
|
|
#include <math.h>
|
|
#include <assert.h>
|
|
|
|
namespace Regression {
|
|
|
|
double QuarticModel::evaluate(double * modelCoefficients, double x) const {
|
|
double a = modelCoefficients[0];
|
|
double b = modelCoefficients[1];
|
|
double c = modelCoefficients[2];
|
|
double d = modelCoefficients[3];
|
|
double e = modelCoefficients[4];
|
|
return a*x*x*x*x+b*x*x*x+c*x*x+d*x+e;
|
|
}
|
|
|
|
double QuarticModel::partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const {
|
|
if (derivateCoefficientIndex == 0) {
|
|
// Derivate: x^4
|
|
return x*x*x*x;
|
|
}
|
|
if (derivateCoefficientIndex == 1) {
|
|
// Derivate: x^3
|
|
return x*x*x;
|
|
}
|
|
if (derivateCoefficientIndex == 2) {
|
|
// Derivate: x^2
|
|
return x*x;
|
|
}
|
|
if (derivateCoefficientIndex == 3) {
|
|
// Derivate: x
|
|
return x;
|
|
}
|
|
if (derivateCoefficientIndex == 4) {
|
|
// Derivate: 1
|
|
return 1;
|
|
}
|
|
assert(false);
|
|
return 0.0;
|
|
}
|
|
|
|
}
|