That's the equivalent of -(6**(1/3)) because the power operator takes precedence over the negation sign. Not the same as what I'm trying to do. It does give the correct answer in this case, but it might not for other fractional powers.
Alright, I made a function using the mpmath library that does what I want:
Ok, let's try again and see if the tabs stay in this time:
Alright, I made a function using the mpmath library that does what I want:
import mpmath def root(z, n): x = [mpmath.root(z,n,k) for k in range(n)] for y in x: if mpmath.im(y) == 0: return y return x[0]The "mpmath.root(z,n,k)" part returns a list of all nth roots of z, and the for loop checks if any of them are real. Leaving this here just in case someone else encounters this. =]
Ok, let's try again and see if the tabs stay in this time:
import mpmath def root(z, n): x = [mpmath.root(z,n,k) for k in range(n)] for y in x: if mpmath.im(y) == 0: return y return x[0]