Solve this equation with fixed point iteration

后端 未结 2 1867
北海茫月
北海茫月 2021-02-14 17:16

How can I solve this equation

x3 + x - 1 = 0

using fixed point iteration?

Is there any fixed-point iteration

2条回答
  •  我在风中等你
    2021-02-14 17:50

    Using scipy.optimize.fixed_point:

    import scipy.optimize as optimize
    
    def func(x):
        return -x**3+1
    
    # This finds the value of x such that func(x) = x, that is, where
    # -x**3 + 1 = x
    print(optimize.fixed_point(func,0))
    # 0.682327803828
    

    The Python code defining fixed_point is in scipy/optimize/minpack.py. The exact location depends on where scipy is installed. You can find that out by typing

    In [63]: import scipy.optimize
    
    In [64]: scipy.optimize
    Out[64]: 
    

    The current fixed_point source code can be found online by going to the documentation page and clicking the [source] link.

提交回复
热议问题