human
Find Nth root of a number using Bisection method | Function that returns the value of the function at a given value of x.
calculating the value of the differential of the function.
The function that returns the root of given number.
Defining range on which answer can be found.
finding mid value.
Driver code"
Solution in Python:
assistant
#Here is code to find Nth root of a number using Bisection method and the other steps required.
 def f ( x , p , num ) :
	return pow ( x , p ) - num
def f_prime ( x , p ) :
	return p * pow ( x , p - 1 )
def root ( num , p ) :
	left = - num
	right = num
	x = 0
	while ( True ) :
		x = ( left + right ) / 2.0
		value = f ( x , p , num )
		prime = f_prime ( x , p )
		if ( value * prime <= 0 ) :
			left = x
		else :
			right = x
		if ( value < 0.000001 and value >= 0 ) :
			return x
if __name__ == " _ _ main _ _ " :
	P = 1234321
	N = 2
	ans = root ( P , N )
	print ( ans )