''' roots = polyRoots(a). Uses Laguerre's method to compute all the roots of a[0] + a[1]*x + a[2]*x^2 +...+ a[n]*x^n = 0. The roots are returned in the array 'roots', ''' from evalPoly import * from numpy import zeros,complex from cmath import sqrt from random import random def polyRoots(a,tol=1.0e-12): def laguerre(a,tol): x = random() # Starting value (random number) n = len(a) - 1 for i in range(30): p,dp,ddp = evalPoly(a,x) if abs(p) abs(g - f): dx = n/(g + f) else: dx = n/(g - f) x = x - dx if abs(dx)
希望本文所述对大家的Python程序设计有所帮助。
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did91488