How would you solve such an equation if it's infeasible to just start trying different $x$ values?
Example: $$x^x = 6.$$
How would you solve such an equation if it's infeasible to just start trying different $x$ values?
Example: $$x^x = 6.$$
$$x^x=6\implies x\log x=\log 6\implies e^{\log x}\log x=\log 6\implies \log x=W(\log 6)\implies x=e^{W(\log 6)}$$ Where $W(x)$ is the Lambert-W function, defined as the inverse of the function $xe^x$
More generally, you can follow the same process to show that $x^x=c\implies x=e^{W(\log c)}$
As said, the solution is explicit in terms of Lambert function. More generally, any equation which can write $A+Bx+C\log(D+Ex)=0$ as solution in terms of Lambert function.
If you do not want (or cannot) use it, numerical methods should be used adn Newton is probably the simplest. However, for the case of $$f(x)=x^x-k=0$$, because the function can be quite stiff, I suggest you apply Newton to $$g(x)=x\log(x)-\log(k)=0$$ $$g'(x)=\log (x)+1$$ which gives for the iteration scheme $$x_{n+1}=\frac{x_n+\log (k)}{\log (x_n)+1}$$ For example, using $k=6$ and $x_0=1$, the iterates will be :$$x_1=2.79175946922806$$ $$x_2=2.26159875297847$$ $$x_3=2.23193699135008$$ $$x_4=2.23182862586824$$ $$x_5=2.23182862440901$$ which is the solution for $15$ significant figures.
Just use Newton's method. One could relate the problem to Lambert's W function as mentioned in the other answer, but solvers for that use Newton's method under the hood so it amounts to the same thing.
Pick some initial guess $x_0$ and iterate: $$x_{k+1} = x_k - \frac{f(x_k)}{f'(x_k)},$$
where $f(x):= x^x - 6$, and the derivative is $$f'(x) = x^x(\log (x + 1)).$$
Here is a simple Matlab/Octave script that does this:
y = 6;
f = @(x) x^x - y;
fprime = @(x) x^x*(log(x) + 1);
x = 1;
for k = 1:20
err = norm(f(x));
disp(['k= ', num2str(k), ', err= ', num2str(err,3)])
if err < 1e-10
break
end
x = x - f(x)/fprime(x);
end
disp(['x= ', num2str(x)])
and here are the results of running the script:
k= 1, err= 5
k= 2, err= 4.66e+04
k= 3, err= 1.73e+04
k= 4, err= 6.46e+03
k= 5, err= 2.41e+03
k= 6, err= 898
k= 7, err= 335
k= 8, err= 124
k= 9, err= 45.4
k= 10, err= 15.8
k= 11, err= 4.8
k= 12, err= 0.999
k= 13, err= 0.0759
k= 14, err= 0.000537
k= 15, err= 2.73e-08
k= 16, err= 1.78e-15
x= 2.2318
As said, the solution is explicit in terms of Lambert function. More generally, any equation which can write $A+Bx+C\log(D+Ex)=0$ as solution in terms of Lambert function.
If you do not want (or cannot) use it, numerical methods should be used adn Newton is probably the simplest. However, for the case of $$f(x)=x^x-k=0$$, because the function can be quite stiff, I suggest you apply Newton to $$g(x)=x\log(x)-\log(k)=0$$ $$g'(x)=\log (x)+1$$ which gives for the iteration scheme $$x_{n+1}=\frac{x_n+\log (k)}{\log (x_n)+1}$$ For example, using $k=6$ and $x_0=1$ (being lazy), the iterates will be :$$x_1=2.79175946922806$$ $$x_2=2.26159875297847$$ $$x_3=2.23193699135008$$ $$x_4=2.23182862586824$$ $$x_5=2.23182862440901$$ which is the solution for $15$ significant figures.
As you notice, the first iteration overshoots the solution because $g(1)g''(1)=-\log (6)<0$ (Darboux theorem). If we start using $x_0=3$ for which $g(3)g''(3)=\frac{1}{3} \log \left(\frac{9}{2}\right)>0$, the iterates would be $$x_1=2.28329906152849$$ $$x_2=2.23214880892654$$ $$x_3=2.23182863714642$$ $$x_4=2.23182862440901$$