版本比较
一元四次方程的全面解析(已更新)
正文
增加 10 行删除 10 行
389 行未改动全部展开3903913923933943943953963973983993994004014024024034044044054064074082 行未改动411412413414415415416417417418419419420421422423424425425426427428429429430431431432433434435287 行未改动全部展开389 行未改动全部展开 使用费拉里方法求解四次方程 ax^4 + bx^3 + cx^2 + dx + e = 0 """ # 化为首一形式 p, q, r, s = b/a, c/a, d/a, e/a
# 消去三次项 P = q - 3*p**2/8 Q = r - p**3/8 - p*q/2 R = s - p*r/4 + p**2*q/16 - 3*p**4/256
# 求解辅助三次方程 # 这里简化处理,实际需要用卡尔丹公式
# ... 具体实现略 ...
return roots
def newton_method(coeffs, x0, tol=1e-10, max_iter=100): """2 行未改动 x0: 初始猜测值 """ def poly_eval(x, coeffs): return sum(c * x**(len(coeffs)-1-i) for i, c in enumerate(coeffs))
def poly_deriv(x, coeffs): return sum((len(coeffs)-1-i) * c * x**(len(coeffs)-2-i) return sum((len(coeffs)-1-i) * c * x**(len(coeffs)-2-i) for i, c in enumerate(coeffs[:-1]))
x = x0 for _ in range(max_iter): fx = poly_eval(x, coeffs) if abs(fx) < tol: return x
fpx = poly_deriv(x, coeffs) if abs(fpx) < tol: break
x = x - fx / fpx
return x
# 使用示例coeffs = [1, -2, -2, 6, -3] # x^4 - 2x^3 - 2x^2 + 6x - 3 = 0287 行未改动全部展开