Question

I'm trying to do an exponential fit on various points (x,y) with the formula A*EXP(-BX), trying to find A and B that best suit my points.

double[] xx = curveFitter.fit(new ParametricUnivariateFunction() {
                public double value(double v, double... doubles) {
                    return doubles[0] * Math.exp(-1 * doubles[1] * v);
                }

                public double[] gradient(double v, double... doubles) {
                    return new double[]{v, 1};
                }
            }, new double[]{0, 0});

I get some numbers but they don't fit my points in any way, Can't seem to find any documentation on the above.

Using commons-math3-3.0

Was it helpful?

Solution

If you are trying to estimate this I suggest you take the log of y which will give you a graph

y' = log(y) = A - B * x;

From this you can calculate the slope and the intercept.

slope = sum((x - mean(x)) * (y' - mean(y')) / sum((x - mean(x))^2) // -B

intercept = mean(y' - x * slope) // A
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top