约束变量scipy fsolve非线性同时方程

时间:2016-10-22 16:05:13

标签: python scipy constraints nonlinear-optimization

我正在尝试用4个未知数来解决4个同时非线性方程iL,isat,Rshunt,Rseries该函数首先传递已知iSC,vOC,imax,vmax,Nseries的变量,然后使用def func1(vars):我定义我的函数集基于物理属性的猜测是9,1e-12,300,0.5

def get_pvparms(iSC,vOC,imax,vmax,Nseries):
    import math as m
    from scipy.optimize import fsolve
    from numpy import sqrt

    n = 1
    boltzmann = 1.3806e-23
    q = 1.60218e-19
    refTemp = 25 + 273.15
    pmax = vmax/imax
    a = n * boltzmann * refTemp * Nseries / q

    def func1(vars):
        iL,isat,Rshunt,Rseries = vars

        iL = iL**2
        isat = isat**2
        Rshunt = Rshunt**2
        Rseries = Rseries**2

        return isat * (m.exp(vOC / a) - 1) + vOC / Rshunt - iL + 0*Rseries,\
               iSC + iSC*Rseries/Rshunt + isat * m.exp(iSC*Rseries/a - 1) - iL,\
               iL - isat*(m.exp((vmax + imax*Rseries)/a)-1) - (vmax + imax*Rseries)/Rshunt - imax,\
               (isat*m.exp((vmax+imax*Rseries)/a)/a + 1/Rshunt)/(1+(isat*Rseries*m.exp((vmax+imax*Rseries)/a)/a)+Rseries/Rshunt) - pmax + 0*iL

    guess = sqrt((iSC,5e-8,300,0.5))

    print fsolve(func1,guess)

我得到了这个结果

 File "C:\Users\Davis_2\Documents\RCL\MAPVsim\pvcalc.py", line 50, in get_pvparms
    print fsolve(func1,guess)
  File "C:\Anaconda2\lib\site-packages\scipy\optimize\minpack.py", line 146, in fsolve
    res = _root_hybr(func, x0, args, jac=fprime, **options)
  File "C:\Anaconda2\lib\site-packages\scipy\optimize\minpack.py", line 224, in _root_hybr
    ml, mu, epsfcn, factor, diag)
  File "C:\Users\Davis_2\Documents\RCL\MAPVsim\pvcalc.py", line 44, in func1
    iSC + iSC*Rseries/Rshunt + isat * m.exp(iSC*Rseries/a - 1) - iL,\
OverflowError: math range error

我怎样才能将约束传递给我的猜测?例如值不能是negative

我试图对变量使用平方方法,但是我得到了溢出。可能执行错误。任何帮助将不胜感激

注意:如果你拿出这段代码:

    iL = iL**2
    isat = isat**2
    Rshunt = Rshunt**2
    Rseries = Rseries**2

并取出这里的sqrt guess = sqrt((iSC,5e-8,300,0.5))它会收敛到一个答案。

0 个答案:

没有答案