java - 如何在 import org.apache.commons.math3.analysis.integration.SimpsonIntegrator 中使用标准 SimpsonIntegrator;

标签 java integration apache-commons numerical-integration numerical-computing

public double evalute(double distance){

    /**
     * equation (3.2)
     */
    this.from = 0;
    this.to = distance;
    this.n = 2;
    return - 10 * Math.log10(Math.exp(-IntSimpson(this.from, this.to, this.n)));
}

有我手动设计的 IntSimpson() 函数,但我想使用标准库!我该怎么做以及在哪里可以找到它?

最佳答案

如果你想实际使用积分器对象,你需要调用integrate method ,它采用 UnivariateFunction 的实例。如果您使用的是 Java 8,那么这是一个单方法接口(interface),因此它自动成为一个函数式接口(interface)。因此,您可以传递 lambda 或方法引用,如下所示:

final SimpsonIntegrator si = new SimpsonIntegrator();
final double result = si.integrate(50, x -> 2*x, 0, 10);
System.out.println(result + " should be 100");

否则,您必须自己创建接口(interface)的实现,方法是让类实现它,或者使用匿名类:

final double result = si.integrate(50, new UnivariateFunction() {
        @Override public double value(double x) {
            return 2*x;
        }
    }, 0, 10);
System.out.println(result + " should be 100");

关于java - 如何在 import org.apache.commons.math3.analysis.integration.SimpsonIntegrator 中使用标准 SimpsonIntegrator;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44875379/

相关文章:

java - 如何使用 danielwegener Kafka 附加程序在 Kafka 消息中自定义 ZonedDatetime

iphone - 推特 API : How to get All tweets from the twitter account in iphone App

eclipse - 插件 org.apache.maven.plugins :maven-resources-plugin:2. 5 或其依赖项之一无法解析:UnresolvedAddressException

Leverice 中的 Jira channel 状态

java - Window Batch 文件集成到 Java GUI 中

java - Eclipse 插件,用于在 java 类更改后进行编译并在构建后自动部署

java - Apache Commons CLI 1.3.1 : How to ignore unknown Arguments?

Java BeanUtils 带下划线 (_) 的未知属性

Java Apache Commons 用户

java - 有没有更简单的方法来定义对象中的对象?