java - 使用 Apache Common Math 确定指数函数的系数

标签 java apache math wolfram-mathematica curve-fitting

我有以下数据。

x = [10
     20
     30 
     40
     50
     60
     70
     80
     90
     100
     110
     120
     130
     140
     150
     160]

y = [86.5
     43.9
     25.4
     17.2
     12
     10.5
     8
     7.8
     6.5
     6.8
     6.1
     6.1
     6
     5.4
     5.7
     5.2]

指数形式为:

y = A + Be(cx)

How to find coefficients for a possible exponential approximation

Least squares Levenburg Marquardt with Apache commons

我想求这个函数的系数。上面提到的链接使我得出的结论是,我需要对函数进行线性化并使用 PolynomialCurveFitter 来确定系数。我使用下面的函数进行了测试,并通过使用 10 到 70 之间的 x 值并取其各自的 log(y-16) 来回溯以确定此过程是否适用于我的数据。

y = 16 + 200e-x/14

import java.util.Arrays;

import org.apache.commons.math3.fitting.PolynomialCurveFitter;
import org.apache.commons.math3.fitting.WeightedObservedPoints;

public class CurveFitting {
    public static void main(String[] args) {
        final WeightedObservedPoints obs = new WeightedObservedPoints();
        obs.add(10, 4.58);
        obs.add(20, 3.87);
        obs.add(30, 3.16);
        obs.add(40, 2.44);
        obs.add(50, 1.73);
        obs.add(60, 1.01);
        obs.add(70, 0.29);

        // Instantiate a first-degree polynomial fitter.
        final PolynomialCurveFitter fitter = PolynomialCurveFitter.create(1);

        // Retrieve fitted parameters (coefficients of the polynomial function).
        final double[] coeff = fitter.fit(obs.toList());
        System.out.println(Arrays.toString(coeff));
    }
}

生成以下值:[5.299999999999998,-0.07149999999999994]。即 B = exp5.3 = 200 且 C = -1/14。这是可能的,因为我事先了解了 A,如果我事先不知道常数,我将如何计算这些系数?

使用 Wolfram Mathematica,A、B 和 C 的值为 6.381、161.144 和 -0.0706。我希望我能得到一些在 java 中获取这些值的指导。谢谢。

最佳答案

常数 A 无关紧要。

您可以重新排列您的功能:

y = A + Be(cx)

看起来像这样:

z = y-A = B*exp(c*x)

两边取自然对数:

ln(z) = ln(B) + c*x

您将进行最小二乘拟合来计算 ln(B)c使用 (x, ln(z)) 对。

您可以设置A任意为零以进行拟合。

获得系数后,您可以重写函数以获取 y 的值。

您可以看到 A 所做的只是上下移动曲线。我的建议是推断回计算 x = 0 处函数的值并设置A的值从此:

y(0) = A + B => A = B - y(0)

您的数据为您提供了 x = 10 的斜率:

y'(x = 10) ~ (43.9 - 86.5)/(20 - 10) = -4.26

推断回 x = 0使用它。

关于java - 使用 Apache Common Math 确定指数函数的系数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41783768/

相关文章:

c# - 计算可调利率抵押贷款的财务公式?

java - Maven不下载依赖项: "The repository system is offline"

java - spring hibernate .. H2 数据库 - 找不到模式

apache - 使用 Apache2 作为 Tomcat7 的代理

html - https 工作正常但 *.com :443 gives a 400 error?

math - 带奇点的 Sage Math 椭圆曲线

Java inputevents 在 linux 中有一段时间没有触发(java/xorg 问题??)

java - 使用java获取OData中entitySet中的条目数

java - 为什么在 pom.xml 中包含 JRJC 依赖项后会出现 http 异常?

c# - 使用 mathdotnet 进行互相关