find $n$ in $x = \sqrt[n]{y}$?

64 Views Asked by At

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?

3

There are 3 best solutions below

1
On BEST ANSWER

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|}$$

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.