Reputation: 878
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.
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);
}
Upvotes: 1
Views: 245
Reputation: 266
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;
}
Upvotes: 1
Reputation: 840
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
Upvotes: 2
Reputation: 266
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)));
Upvotes: 1