Search code examples
javamathlogarithm

How To Code this formula in Java?


I have tried to represent this formula in Java but the values are not correct maybe I have some issue transforming the formula to code.

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);
}

Solution

  • What about splitting it into more parts:

    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));
    

    op:

    122.08071553760861