1

Is there a way to force Apache commons math to fit a linear curve of the form (y = mx + 0) through the origin (0,0). So far I've used both PolynomialCurveFitter and SimpleCurveFitter, but none of them is returning a result that passes through the origin. E.g:

final WeightedObservedPoints wopts = new WeightedObservedPoints();
//Add observed points to wopts: 
...
final PolynomialCurveFitter curveFitter = PolynomialCurveFitter.create(1);
double[] coeff = {0.0, 042};  //y = 0.042x + 0
curveFitter.withStartPoint(coeff);
final double[] bestPrediction = curveFitter.fit(wopts.toList());

but bestPrediction[0] is not 0.0 Any hint will be highly appreciated.

1 Answers1

0

In this line:

  double[] coeff = {0.0, 042};

you use an octal integer 042 (i.e. 8*4 + 2) which is internally converted to the double value 34.0.

Define the line as:

  double[] coeff = {0.0, 0.42};
axelclk
  • 950
  • 9
  • 28