LoginSignup
1
0

More than 5 years have passed since last update.

sympyとニュートン法の結果を比較してみた

Posted at

ニュートン法は、素晴らしいですね。
(参考)Pythonで数値解析ニュートン法
https://qiita.com/Y_F_Acoustics/items/9288f614c23085db2d9b

wolframalpha

(参考)x*2-2=0
http://m.wolframalpha.com/input/?i=x
*2-2%3D0
sqr(2)

(参考)http://m.wolframalpha.com/input/?i=sqr%282%29
1.414213562373095048801688724209698078569671875376948073176...
(参考)exp(x*2)-2*exp(0)*x+exp(0)=0
This Wolfram|Alpha server is temporarily unavailable.
Click here to try another server.
(参考)exp((-1)
2)-2*exp(0)(-1)+exp(0)
http://m.wolframalpha.com/input/?i=exp%28%28-1%29**2%29-2*exp%280%29*%28-1%29%2Bexp%280%29
3 + e

sympy

from sympy import *
x = symbols('x')
ans =solve(x**2-2)
print(ans[0],ans[1])
print(float(ans[0]),float(ans[1]))
print('-------------------------')
f=exp(x**2)-2*exp(0)*x+exp(0)
print(f)
f1 = f.subs([(x, -1)])
print(f1)
print('-------------------------')
ans =solve(exp(x**2)-2*exp(0)*x+exp(0))
print(ans)

# -sqrt(2) sqrt(2)
# -1.4142135623730951 1.4142135623730951
# -------------------------
# -2*x + exp(x**2) + 1
# E + 3
# -------------------------
# Traceback (most recent call last):
#   File "C:/xxx/.PyCharmCE2018.2/config/scratches/aaa.py", line 12, in <module>
#     ans =solve(exp(x**2)-2*exp(0)*x+exp(0))
#   File "C:\/xxx\PycharmProjects\untitled4\venv\lib\site-packages\sympy\solvers\solvers.py", line 1065, in solve
#     solution = _solve(f[0], *symbols, **flags)
#   File "C:\xxx\PycharmProjects\untitled4\venv\lib\site-packages\sympy\solvers\solvers.py", line 1634, in _solve
#     raise NotImplementedError('\n'.join([msg, not_impl_msg % f]))
# NotImplementedError: multiple generators [x, exp(x**2)]
# No algorithms are implemented to solve equation -2*x + exp(x**2) + 1
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0