• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python计算方程式根的方法

python计算方程式根的方法

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python 平方根,python 平方根函数,python求平方根,python根目录,python 求根等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了python计算方程式根的方法。分享给大家供大家参考。具体实现方法如下:

''' 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) < tol: return x
      g = dp/p
      h = g*g - ddp/p
      f = sqrt((n - 1)*(n*h - g*g))
      if abs(g + f) > abs(g - f): dx = n/(g + f)
      else: dx = n/(g - f)
      x = x - dx
      if abs(dx) < tol: return x
    print 'Too many iterations'
  def deflPoly(a,root): # Deflates a polynomial
    n = len(a)-1
    b = [(0.0 + 0.0j)]*n
    b[n-1] = a[n]
    for i in range(n-2,-1,-1):
      b[i] = a[i+1] + root*b[i+1]
    return b
  n = len(a) - 1
  roots = zeros((n),dtype=complex)
  for i in range(n):
    x = laguerre(a,tol)
    if abs(x.imag) < tol: x = x.real
    roots[i] = x
    a = deflPoly(a,x)
  return roots
  raw_input("\nPress return to exit")
</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • Python求算数平方根和约数的方法汇总
  • Python求算数平方根和约数的方法汇总
  • python计算方程式根的方法
  • Python求解平方根的方法

相关文章

  • Python fileinput模块使用实例
  • python中getaddrinfo()基本用法实例分析
  • python的描述符(descriptor)、装饰器(property)造成的一个无限递归问题分享
  • 动感网页相册 python编写简单文件夹内图片浏览工具
  • 用Python从零实现贝叶斯分类器的机器学习的教程
  • Python抓取京东图书评论数据
  • Python实现把回车符\r\n转换成\n
  • python网络编程之文件下载实例分析
  • 用Python进行行为驱动开发的入门教程
  • python之模拟鼠标键盘动作具体实现

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python+Django在windows下的开发环境配置图解
    • python入门基础之用户输入与模块初认识
    • 深入解读Python解析XML的几种方式
    • Python脚本实现下载合并SAE日志
    • python中使用enumerate函数遍历元素实例
    • Python中模块string.py详解
    • python中的一些类型转换函数小结
    • Python使用urllib模块的urlopen超时问题解决方法
    • 总结python实现父类调用两种方法的不同
    • python导入时小括号大作用

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有