简体   繁体   English

fsolve Python函数,增加错误

[英]fsolve Python function, increment bug

I am trying to solve a four nonlinear equation system using the scipy.optimize function fsolve . 我正在尝试使用scipy.optimize函数fsolve解决一个四个非线性方程组。

def equations(p):
   e1, e2, F, B = p

   Eq_F1 = (-F + Fa(4, e1, e2) + Fa(5,e1, e2) - A1*Acc1(e1, e2))
   Eq_T1 = (F*L + Fa(4,e1, e2)*A2 + Fa(5, e1, e2)*A3
   Eq_F2 = (Fb(1, e1, B)*A4*math.cos(B) + Fb(2,e1)*A5 + Fb(3,e1)*A6 + F*np.cos(alpha(e1, e2))- A7*Acc2)
   Eq_T2 = (Fb(1,e1, B)*math.cos(B)*A8- F*np.cos(alpha(e1, e2))*A9- Fb(2,e1)*A10- Fb(3,e1)*A11

   return (Eq_F1, Eq_T1, Eq_F2, Eq_T2)

Where Fa , Fb et alpha are functions of e1 , e2 and of a number. 其中FaFbalphae1e2和数字的函数。 Ai are constants I introduced to give you a global vision of the system. Ai是我引入的常数,目的是使您对系统有一个整体的了解。 I solve the system as following: 我将系统解决如下:

e1, e2, F, B  = fsolve(equations,(0.3,5,100,0.1), xtol=1.49012e-14)

Where the first guessing is reasonable knowing my problem. 第一次猜测是合理的,知道我的问题。

The results given being false, I introduced print(e1, e2, F, B) in the equations function. 给出的结果为假,我在方程函数中引入了print(e1, e2, F, B) What a surprise ! 真是一个惊喜! If the first values are 0.3, 5, 100, 0.1 , they immediately jump to extreme values on the second one, impeding the convergence... Thus the results turn far from relevant. 如果第一个值是0.3, 5, 100, 0.1它们立即跳到第二个值的极值,这会阻止收敛。因此结果与实际情况相去甚远。

Has anyone got an idea ? 有人知道吗?

I can't reproduce your code because I don't have all the constants. 我无法复制您的代码,因为我没有所有的常量。 Without knowing the exact details of your problem, I cannot be sure, but I will guess there is a high probability of a numerical issue here . 在不知道您的问题的确切细节的情况下,我不能确定,但​​是我猜想这里很可能出现数字问题

fsolve is a function that implements an algorithm in numerical analysis , and it iterates towards an approximate solution. fsolve是在数值分析中实现算法的函数,并朝着近似解迭代。 Numerical algorithms can be "touchy" in the sense that if the user does not use the right settings for a particular problem, or if the particular choice of algorithm is unsuited for the problem, errors can result. 从某种意义上说,数字算法可能是“敏感的”,如果用户没有针对特定问题使用正确的设置,或者如果特定的算法选择不适合该问题,则可能会导致错误。

  • Your starting point might be bad -- numerical algorithms can be very sensitive to the choice of starting point. 您的起点可能很糟糕-数值算法可能对起点的选择非常敏感。
  • Your xtol might be way too small -- this can lead to tiny step sizes in the iteration of the algorithm which prevents convergence and also causes numerical error (eg rounding error) to accumulate. 您的xtol可能太小了-这可能导致算法迭代中的步长很小,从而阻止了收敛,并且还导致累积了数字误差(例如,舍入误差)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM