java - 确定函数的极值

标签 java calculus

我遇到了最小值未正确设置的问题。最大值设置完美,但我知道最小值应该小于 0。运行此代码片段,似乎最小值从未被设置。有什么想法吗?

编辑:曲线点应该从-1到3。这是一个图像: The curve

public class FindingExtrema {
    public static void main(String[] args) {
        double lowestPoint = 0;
        double highestPoint = 0;
        double y;

        double x = -1;
        int timesCalculated = 0;

        while (x <= 3) {
            y = run(x);

            if (y < lowestPoint) {
                lowestPoint = y;
                System.out.printf("y: %1$.5f", y);
            }

            if (y > highestPoint) {
                highestPoint = y;
            }

            x += .00001;
            timesCalculated++;
        }

        System.out.println("Done!");
        System.out.printf("Lowest: %1$.5f, Highest: %2$.5f; Calculated %3$d times\n", lowestPoint, highestPoint, timesCalculated);
    }

    private static double run(double x) {
        return Math.cbrt(2 * x) - Math.sqrt(8 * x) + x + 16;
    }
}

最佳答案

but I know that the minima should be less than 0.

如果你把它画出来的话,事实并非如此。我将您的函数插入 Google,范围为 0 到 3,最小值约为 15.431。

关于java - 确定函数的极值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36560386/

相关文章:

java - 似乎无法理解复杂的多态性

java - 在单独的循环上提取draw()方法(PApplet作为JADE代理)

java - 使用 httpclient 的连接持久性

python - 将结果添加到列表并设置 for 循环

c - C 中的梯形黎曼和

java - SOAPMessage 如何解析&lt;![CDATA[ ]]>?

c++ - 计算两个函数的重叠面积

c++ - 使用QScriptEngine计算计算

python - 当我在 sympy 中使用solve()时,变量列表为空?

java - LinkedList 多线程在 Runnable 中创建单独的实例