加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Numerical Analysis

发布时间:2020-12-14 05:14:10 所属栏目:大数据 来源:网络整理
导读:PART1? 求解方程 1,二分法 def bisect(f,a,b,TOL= 0.000004 ): u_a = a u_b = b while (u_b-u_a)/ 2.0 TOL: c = (u_a+u_b)/ 2.0 if f(c) == 0 : break if f(u_a)*f(c) 0 : u_b = c else : u_a = c u_c = (u_a + u_b) / 2.0 return u_cf = lambda x: x*x*x +

PART1? <求解方程>

1,二分法

def bisect(f,a,b,TOL=0.000004):
    u_a = a
    u_b = b
    while(u_b-u_a)/2.0 > TOL:
        c = (u_a+u_b)/2.0
        if f(c) == 0:
            break
        if f(u_a)*f(c) < 0:
            u_b = c
        else:
            u_a = c

    u_c = (u_a + u_b) / 2.0
    return u_c

f = lambda x: x*x*x + x - 1
ret = bisect(f,-1.0,1.0)
print(ret)

print(f(ret))

        
    
View Code

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读