Exponential Fit with apache commons math
Asked Answered
D

1

5

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

Disuse answered 29/10, 2012 at 17:38 Comment(0)
B
9

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
Burnette answered 29/10, 2012 at 17:46 Comment(1)
used your formula and then used a PolynomialFitter instead thanks!Disuse

© 2022 - 2024 — McMap. All rights reserved.