I'm trying to compute the value of x^x.
I have calculated it's derivative and I'm
using the Newton–Raphson method to find the root of f(x)=x^x-a for a given a.
This is the function I use to calculate the next approximation:
double xkp1(double xk, double a){
double lnxp1 = log(xk) +1;
return xk -( (fx(xk, a)) / (exp(xk*log(xk)) * (log(xk) + 1) ));
}
where function fx is defined this way:
double fx(double x, double a){
return exp(x*log(x))-a;
}
Now, this approach works correctly only if the starting value of xk is already close to the root.
If it differs by +-0.5, xk just explodes to a really high value and f(x) becomes infinity.
Now i think what might be wrong here - the derivative of x^x is very small in comparison to the actual value of x^x, so the whole (fx(xk, a)) / (exp(xk*log(xk)) * (log(xk) + 1) )
just becomes +infinity - the tangent line overshoots the root.
This means I'd need higher double precision, but is it possible in any way? If not, can something be modified in the method to make it applicable in this situation?
a
? Also, you could instead take the logarithm of both sides and solvex*log(x) = log(a)
- far less likely to overshoot and end up with astronomical values. - meowgoesthedog