예제 #1
0
파일: newton.py 프로젝트: EliMor/MathToys
def d(x,function):
	#print x,function
	f = derivative.deriv(function)

	#may want to return f if need to debug derivative
	if f == 0: return 0
	return f,eval(f)
예제 #2
0
파일: roots.py 프로젝트: EliMor/MathToys
def modified_newton(func,p0,tol = 10e-16,max_iter = 100):
	func = derivative.expand(func)
	df = derivative.deriv(func)

	for i in range(1,max_iter+1):
		x = p0 - 5*evaluate(func, p0)/float(evaluate(df, p0))
		if abs(x - p0)/abs(p0) < tol :
			return x,i
		p0 = x