I'm not very experienced at math, though I find it very interesting most of the time. I am writing a program where I need to find $n$ in $x = \sqrt[n]{y}$, given $x$ and $y$. I have implemented it using a loop, with a 'guess and check' type of method. I keep feeling, however, like there is already some simpler way to do this. What am I looking for here?
2026-04-02 22:08:16.1775167696
On
On
find $n$ in $x = \sqrt[n]{y}$?
64 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
3
There are 3 best solutions below
0
On
Assuming that $x,y >0$ you can just take logarithms $$ x = \sqrt[n]{y}\Leftrightarrow \log x = \frac 1n \log y \Leftrightarrow n = \frac{\log y}{\log x}. $$
0
On
Besides the exact answers the others posted, the general approach you've already tried (trial and error) includes an established Bisection Method, which converges rather quickly.
If $n$ is even then we have that $y>0$ and $x>0$ and
$$x=y^{1/n}\to \log x=\frac1n \log y \to n=\frac{\log y}{\log x}$$
If $n$ is odd then we can have $y<0$ and then $x<0$. On that case we can multuply both sides by $-1$ and then
$$-x=(-y)^{1/n}\to |x|=|y|^{1/n}\to n=\frac{\log |y|}{\log |x|}$$
So, the general solution is
$$n=\frac{\log |y|}{\log |x|}$$