指数适合apache commons math

Rod*_*uez 5 java math apache-commons-math

我试图用公式A*EXP(-BX)对各个点(x,y)进行指数拟合,试图找到最适合我的点的A和B.

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});
Run Code Online (Sandbox Code Playgroud)

我得到了一些数字,但它们不符合我的观点,似乎无法找到上述任何文档.

使用commons-math3-3.0

Pet*_*rey 7

如果您正在尝试估计这个,我建议您使用y的日志来为您提供图表

y' = log(y) = A - B * x;
Run Code Online (Sandbox Code Playgroud)

由此您可以计算斜率和截距.

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

intercept = mean(y' - x * slope) // A
Run Code Online (Sandbox Code Playgroud)