用定点迭代求解该方程

发布于 2024-10-05 01:49:28 字数 143 浏览 0 评论 0原文

我怎样才能解这个方程

x3 + x - 1 = 0

使用定点迭代?

我可以在网上找到任何定点迭代代码(尤其是Python)吗?

How can I solve this equation

x3 + x - 1 = 0

using fixed point iteration?

Is there any fixed-point iteration code (especially in Python) I can find online?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

街角卖回忆 2024-10-12 01:49:28

使用 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

定义fixed_point的Python代码位于scipy/optimize/minpack.py中。确切的位置取决于 scipy 的安装位置。您可以通过输入找到

In [63]: import scipy.optimize

In [64]: scipy.optimize
Out[64]: <module 'scipy.optimize' from '/usr/lib/python2.6/dist-packages/scipy/optimize/__init__.pyc'>

当前的固定点源代码可以通过访问文档页面并单击[source]链接。

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]: <module 'scipy.optimize' from '/usr/lib/python2.6/dist-packages/scipy/optimize/__init__.pyc'>

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

或十年 2024-10-12 01:49:28

尝试使用 SymPy 库。这是一个相关示例

>>> solve(x**3 + 2*x**2 + 4*x + 8, x)
[-2*I, 2*I, -2]

我不确定 SymPy 使用哪种算法来求解方程,尽管。

Try the SymPy library. Here's a relevant example:

>>> solve(x**3 + 2*x**2 + 4*x + 8, x)
[-2*I, 2*I, -2]

I'm not sure which algorithm SymPy uses to solve the equation, though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文