1

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);
}
  • 1
    The base of a log is at the bottom, no? This is log_10 to the power 3. Either way, your code is not the same as the formula as `Math.pow(3, ...)` means 3 to the power something, which appears nowhere in the formula. – RDM Mar 11 '15 at 15:41
  • What _is_ the formula you are trying to code? – Tunaki Mar 11 '15 at 15:47
  • What is your expected result? And what should `y` equal to attain this answer? – TNT Mar 11 '15 at 15:48
  • Not sure, but this might be related: http://stackoverflow.com/questions/1497400/why-log1000-log10-isnt-the-same-as-log101000?rq=1 – parakmiakos Mar 11 '15 at 15:49

3 Answers3

2

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

Ben Win
  • 830
  • 8
  • 21
  • Thanks this solution works fine the final code `double factor = 10 * Math.pow(Math.log(10 + Math.pow(time, 3)), 3);` – Alejandro Quintanar Mar 11 '15 at 16:02
  • You are welcome. Maybe its just my personal opinion but i like to split functions into more parts, when they become more complex :) – Ben Win Mar 11 '15 at 16:12
1

I think you are looking for log base 3, not log to the power of 3. Therefore, the formula should be

double factor = 10 * logOfBase(3, 10 + Math.pow(y, 3)));
Anthony Genovese
  • 266
  • 8
  • 20
1

To go on Ben Win's for all values of y.

public double getfactor(int y){
double temp = (double)10 + Math.pow(y, 3); //
double factor = 10 * Math.pow(Math.log(temp), 3); 
return factor;
}
Anthony Genovese
  • 266
  • 8
  • 20