if x is a variable... then how do we solve x^x=k.... where k is a real number???
is there any viable and structural method for it....other than trial and error
Last edited by The Godfather; Jun 9th, 2005 at 02:04 PM.
Sure - you should be able to use Newton's method to iteratively find a solution. I'm doing this from memory, so I apologize if I get something wrong.
you basically want to find the solution to the problem:
x^x - C = 0
Where C is the constant. With Newton's method, you make a guess at the solution, evaluate the equation and derivative (slope) at the guess, then update the guess based on the derivative, and so on. I'd go further, but my math is rusty enough that I don't remember how to differentiate y = x^x with respect to x.
See attachment for graphical representation for C = 300. Newton's method is of a 'shooting' type, so the closer you are the faster it arrives at the solution. Also, from the nature of x^x, an initial guess that's too high is much better than guessing too low.
Edit - this link should help figure out the derivative of x^x:
I don't think differentiation is the way forward, d/dx (x^2 - C) gives 2x =0.
Try the bisection method: pick an initial start point A (do it based on the number of digits in C so that you aren't starting at 1 and trying to find 1000000) and square it, checking to see if it is bigger than C. If so, halve it (B), square and check again. If B is smaller than C, go halfway in between A and B, square and check again. Repeat until you find the number to as many dp as you want.
Basically, you guess each time halfway between a number definitely smaller than x and a number definitely larger than x. If a guess does not give you x, then it gives you a number either smaller (in which case this is your new lower bound) or larger (in which case this is your new upper bound). You can narrow it down in as many iterations as you want.
The equation was x^x - C = 0, not x^2 - C = 0. Even if it were, Newton's method still works. In your case, 2x just represents the slope of the function at x. The methodology is identical in either case. Bi-section also works, is more stable for 'ill-behaved' functions (lots of min and max points), but it is much slower to converge. Newton's method converges very rapidly, and is ideal for well behaved (i.e. smooth) functions like this. I've used Newton's Method (Newton-Raphson, actually) to solve a set of 7 non-linear equations and it was almost magical in how quickly it converged.
VBAhack
Edit: the following link has a good explanation of Newton's method:
Got it. The derivative of x^x is (x^x)(1+ln(x)). The solution to x^x = 256 (solution is 4) is attached using Newton's Method and bi-section. Initially, bi-section converges faster then Newton, but after the 17th iteration, Newton converges extremely rapidly whereas bi-section still keeps plodding away. (see page 2). Newton's Method is a very good technique.
VBAhack
Last edited by VBAhack; Jun 11th, 2005 at 11:53 PM.
Now you've got at least 2 methods to choose from to solve x^x = C, each with pros/cons. Bi-section is computationally simple (function evaluation only), is very stable (won't diverge), but converges slowly (linearly?). Newton's method is more computationally expensive (function evaluation and derivative), can diverge if the intitial guess isn't 'close enough', but converges rapidly (quadratically) when close to the solution.