Basically, the calculation without log is -
x / [ 1-1/(1+x)^n]
So, when you take log, you get logx - log(1-(1/(1+x)^n))
But, when I'm doing this same in Java, I'm getting this error
"Operator ^ cannot be applied to double.." How come o.0
public static double f(double x) {
return Math.log(x)-Math.log(1-(1/(1+x)^n));
}
Ulrich Eckhardt - 26 Sep 2007 09:28 GMT
> I'm getting this error
> "Operator ^ cannot be applied to double.." How come o.0
That operator does simply not do what you think it does. I guess you rather
want a pow() or power() function (not sure what it's called in Java). Both
should be explained in your Java book.
Uli

Signature
Sator Laser GmbH
Geschäftsführer: Ronald Boers, Amtsgericht Hamburg HR B62 932
UKP - 26 Sep 2007 09:35 GMT
^^
This should be working -
double y = Math.pow(1+x,120);
return Math.log(x)-Math.log(1-(1/y));
Roedy Green - 26 Sep 2007 12:44 GMT
>x / [ 1-1/(1+x)^n]
>
>So, when you take log, you get logx - log(1-(1/(1+x)^n))
>
>But, when I'm doing this same in Java, I'm getting this error
>"Operator ^ cannot be applied to double.." How come o.0
because ^ in Java means xor, not exponentiation. Java does not have
an exponentiation operator. All it has is Math.pow and Math.exp.
See http://mindprod.com/jgloss/xor.html
http://mindprod.com/jgloss/power.html
http://mindprod.com/jgloss/exp.html
http://mindprod.com/jgloss/exponentiation.html
http://mindprod.com/jgloss/logarithms.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com