Python Forum
Fractional Exponent Question
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fractional Exponent Question
#3
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:
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]
Reply


Messages In This Thread
Fractional Exponent Question - by Flexico - Dec-03-2016, 08:07 PM
RE: Fractional Exponent Question - by sparkz_alot - Dec-03-2016, 09:41 PM
RE: Fractional Exponent Question - by Flexico - Dec-04-2016, 01:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I'm looking for the syntax of a complex exponent, like: 2 ** (n - m) CHANCEMAN 2 542 Dec-29-2023, 01:53 PM
Last Post: Yoriz
  pandas dataframe into csv .... exponent issue mg24 10 1,790 Jan-20-2023, 08:15 PM
Last Post: deanhystad
  comparing fractional parts of floats Skaperen 4 3,355 Mar-19-2019, 03:19 AM
Last Post: casevh
  Negative numbers and fractional powers Flexico 1 4,884 Dec-08-2016, 04:12 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020