牛顿法

作者: sorry510 | 来源:发表于2020-04-12 22:15 被阅读0次

    (x-3)^3=0的解
    x_{n+1} = x_n - \frac {f(x_n)}{f'(x_n)}

    # (x - 3)** 3 = 0
    
    def f(x):
        return (x - 3)**3
    
    def fd(x):
        return 3 * (x - 3)**2
    
    def newtonMethod(n, assum):
        time = n
        x = assum
        A = f(x)
        B = fd(x)
        if f(x) == 0.0:
            return time, x
        else:
            Next = x - A / B
    
        if A - f(Next) < 1e-6:
            print('meet f(x) = 0, x = %s', str(Next))
        else:
            return newtonMethod(n + 1, Next)
    
    newtonMethod(0, 4.0)
    
    
    
    

    相关文章

      网友评论

          本文标题:牛顿法

          本文链接:https://www.haomeiwen.com/subject/slhimhtx.html