簡體   English   中英

如何在Python上找到非常復雜的方程式的根?

[英]How to find roots of very complex equation on Python?

如何在Python上解決這個問題(f(r)= 0)?

def f(r):
     return -6*r**2*(pi - 1/cos(2.4e-6*sqrt(3)/r)) - 3*r**2*(2*cos(pi/6 - 1/cos(2.4e-6*sqrt(3)/r))*cos(1/cos(2.4e-6*sqrt(3)/r)) - pi/2 + 1/cos(2.4e-6*sqrt(3)/r)) - (-2.88e-5*sqrt(3) + 0.000207846096908265)*cos(pi/6 - 1/cos(2.4e-6*sqrt(3)/r)) + 5.19615242270663e-10

一種選擇是使用scipy.optimize.root 您只需要傳遞初步猜測即可。

from scipy.optimize import root
initial_guess = 1
solution = root(fun=f, x0=initial_guess)

print(solution)
#    fjac: array([[-1.]])
#     fun: array([-4.73292067e-21])
# message: 'The solution converged.'
#    nfev: 50
#     qtf: array([7.59795519e-16])
#       r: array([-99.77979489])
#  status: 1
# success: True
#       x: array([1.46358719e-06])

作為檢查,我們可以將解決方案重新插入您的函數中:

print(f(solution.x[0]))
#-4.732920669875286e-21

實質上是0。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM