牛顿、拉复生方法求开方,牛顿拉复生开方,[Python]代码de
牛顿、拉复生方法求开方,牛顿拉复生开方,[Python]代码de
[Python]代码
def SquarerootNR(x,eplison): assert x>=0, 'x must be non negtive not'+str(x) assert eplison>0,'eplison must be positive not'+str(eplison) x=float(x) guess=x diff=guess**2-x ctr=1 while abs(diff)>eplison and ctr<=100: guess=guess-diff/(2*guess) diff=guess**2-x ctr+=1 assert ctr<=100 ,'the times of iteration is too much' print 'NR method:' print 'guess: %f iteration: %d' %(guess,ctr) return guess
牛顿、拉复生思想求开方
def SquarerootNR(x,eplison): assert x>=0, 'x must be non negtive not'+str(x) assert eplison>0,'eplison must be positive not'+str(eplison) x=float(x) guess=x diff=guess**2-x ctr=1 while abs(diff)>eplison and ctr<=100: guess=guess-diff/(2*guess) diff=guess**2-x ctr+=1 assert ctr<=100 ,'the times of iteration is too much' print 'NR method:' print 'guess: %f iteration: %d' %(guess,ctr) return guess
相关内容
- winmm调整windows系统的音量大小,winmm音量,[Python]代码#
- Python脚本提取谷歌音乐搜索结果,python谷歌,[Python]代码
- 股市信息下载,,[Python]代码im
- 栈类,,[Python]代码cl
- 三维矢量的幅度,三维矢量幅度,[Python]代码fr
- 素数检测器,,[Python]代码de
- Sierpinski carpet(Sierpinski 地毯),sierpinskicarpet,[Python]代
- 一个文件里有多少字?,文件里字?,[Python]代码fr
- python端口扫描程序,python端口扫描,from socket
- python通过socket进行通信的简单范例,带客户端和服务器
评论关闭