java - 如何用 Java 编写这个公式?

标签 java math logarithm

我曾尝试用 Java 表示这个公式,但值不正确,也许我在将公式转换为代码时遇到了一些问题。

formula

private double getFactor(int y) {
    double factor = 10 * Math.pow(3, logOfBase(2, 10 + Math.pow(y, 3)));
    return factor;
}

public double logOfBase(int base, double num) {
    return Math.log(num) / Math.log(base);
}

最佳答案

如何将它拆分成更多部分:

double temp = (double)10 + Math.pow(0, 3); // 0 = y
double factor = 10 * Math.pow(Math.log(temp), 3); //Math.log - Returns the natural logarithm (base e) of a double value

System.out.println(String.valueOf(factor));

操作:

122.08071553760861

关于java - 如何用 Java 编写这个公式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28991027/

相关文章:

javascript - 如何在 JavaScript 中指定 Math.log() 的基数?

java - videocapture 在多个调用中以不同方式读取同一帧

java - 如何从 Hbase 启用 Ganglia 的新指标?

algorithm - 找出两个随机选择的整数(从 n 个整数中)互质的概率

math - 在 O(n) 中找到圆上最近的 2 个点的理论算法

javascript - 如何四舍五入到最接近的整数

objective-c - objective-c/cocoa-touch 中有哪些对数函数/方法?

c - 如何在没有 math.h 的情况下编写一个简单的对数函数?

java - 将 DTO 转换为域模型,然后使用 lambda 返回

java - Spring MVC 3.2.8 : Create a new FileSystemXmlApplicationContext and loading the definitions from the given XML files