使用Scipy求解器优化非线性方程
import numpy as np
import sys
import pandas as pd
from scipy.optimize import *
import matplotlib.pylab as plot
SigG = 162.4
M2 = 30
SigS = 111.7
Rmv = 26
kN2E6 = 6.13
func = lambda SigA : 1-(((SigA/SigG)**M2) + (((SigA/(kN2E6+(10.0**-23))) + SigS) / (Rmv + SigS))**2)
SigAinitial_guess = [0,162.4]
Solution = fsolve(func,SigAinitial_guess)
Solution[0]
print(repr(Solution[0]))
我有一个优化代码中提到的上述方程式的问题。我需要从方程式中找出SIGA,总方程式必须等于一个。
我已经使用Excel求解器实现了相同的实现,这些是SIGA的确切输出值,并且对我们的实验感到满意。现在,我正在尝试使用Python实现相同的功能。
这里的问题是我有不同的KN2E6值。从这些值中,如果我采用4.608,我将获得Excel中的确切输出。如果将值从6.136到其余值的值,我会遇到错误,并且在下面的两个KN2E6值下面都提到了它。
对于KN2E6 = 6.136,
对于KN2E6 = 4.608,
我已将我的Sigainitial_guess = [0,162.4],因为我的Siga输出应该在(0,162.4)之间。
import numpy as np
import sys
import pandas as pd
from scipy.optimize import *
import matplotlib.pylab as plot
SigG = 162.4
M2 = 30
SigS = 111.7
Rmv = 26
kN2E6 = 6.13
func = lambda SigA : 1-(((SigA/SigG)**M2) + (((SigA/(kN2E6+(10.0**-23))) + SigS) / (Rmv + SigS))**2)
SigAinitial_guess = [0,162.4]
Solution = fsolve(func,SigAinitial_guess)
Solution[0]
print(repr(Solution[0]))
I have an issue with optimizing the above equation mentioned in the code. I need to find out SigA from the equation and the total equation must be equal to one.
I have already implemented the same using Excel solver and those are the exact output values of SigA and it satisfied with our experiment. Now, I'm trying to implement the same using Python.
The problem here is I have different kN2E6 values. From those values, if I take 4.608 I'm getting the exact output in Excel. If I take the values from 6.136 to the rest values I'm getting an error and I have mentioned it below for both kN2E6 values.
For kN2E6 = 6.136
For kN2E6 = 4.608
I have taken my SigAinitial_guess = [0,162.4], because my output of SigA should be in between (0,162.4).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论