数值分析正割法python3实现并绘图
来源:互联网 发布:磁力在线播放 源码 编辑:程序博客网 时间:2024/06/05 19:13
import numpy as npimport matplotlib.pyplot as pltprint("题目:用正割法求x^3-x-1=0在x=1.5的一个根")print("---------------------------------------")i = 0def result(x): y = (x**3-x-1)/(3*x**2-1) return x-ydef Y(x): global i i = i+1 plt.plot([x, x], [0, (x**3-x-1)]) plt.plot([x, result(x)], [(x**3-x-1), 0]) temp = round(x-result(x),5) if(temp== 0.0): print('正割法第',i,'次') print('解得:',round(x,5)) x = result(x) y = (result(x)**3- result(x) - 1) plt.plot(x, y, ".") plt.plot(x,y,"g-") plt.annotate("(1.32472,1.32472)", xy=(result(x), (result(x)**3- result(x) - 1)), xytext=(result(x) - 0.5, (result(x)**3- result(x) - 1) +2), color='k', fontsize=10) else: Y(result(x))Y(2.7)x = 0plt.title("secant method")x = np.linspace(0,3)plt.xlim(0,3)# 固定坐标plt.ylim(-5,20)plt.plot(x,x**3-x-1,"b-")plt.grid(True)plt.plot([0,3],[0,0],"--")plt.show()
正割法是近似的牛顿切线法,把求导用斜率代替。
用切线不断逼近函数的单根
阅读全文
0 0
- 数值分析正割法python3实现并绘图
- 数值分析牛顿切线法python3实现并绘图
- 数值分析-拉格朗日插值法python3实现绘图
- 数值分析定点迭代python3实现加绘图
- 正割法
- 数值分析--线性多项以及多元最小二乘拟合python3实现并画图
- 数值分析-劈因子法(贝尔斯托法)python3实现
- python3.3+numpy+matplotlib 实现绘图
- Python数值分析 PyCharm with python2 which shifted from python3
- 数值分析 追赶法求解三对角线性方程组 MATLAB实现
- The Secant Method(正割法、弦截法) 附C语言代码
- 线性方程数值分析中高斯迭代matlab实现
- 数值分析(一)拉格朗日插值法c++实现
- 数值分析-Legendre正交多项式 实现函数逼近
- 数值分析 2.2 平方根法
- 数值分析2.2 追赶法
- 数值分析
- 数值分析
- 对机器学习的理解
- java开发环境搭建
- Eclipse中的Maven项目报错处理方法
- 工具类-万能Adapter
- CodeForces 816A Karen and Morning
- 数值分析正割法python3实现并绘图
- C++笔试题(十三).网易有道
- [Docker] ERROR: Failed to creating docker image:Permission denied
- 工具类-dp转化
- C51串口
- mobiscroll 时间选择器小结
- JAVA框架原理
- redis学习笔记(二)
- 1020. 月饼 (25)