Operator ^ cannot be applied to double..?

U

UKP

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

}
 
U

Ulrich Eckhardt

UKP said:
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
 
U

UKP

^^

This should be working -

double y = Math.pow(1+x,120);

return Math.log(x)-Math.log(1-(1/y));
 
R

Roedy Green

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,979
Messages
2,570,184
Members
46,721
Latest member
DollieSawt

Latest Threads

Top