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