0

我正在使用 scipy 中的 newton() 函数来求解适用于单个值的特定非线性方程

 def iv(p):
   I=p
   diode=Il-(Io*(np.exp((v+(I*RS))/a)-1))-((v+(I*RS))/Rsh)-I

   return diode

 I=[opt.newton(iv,2)for v in np.arange(0,44.5,0.1)]

我正在尝试对 (I,Io,RS,a,Rsh) 的 8760 个值执行相同的操作,这些值是单独的数据帧

def elec():


I=DataFrame(zeros(3898200).reshape((8760,445)),index=pd.date_range('1/1/2001 00:00','12/31/2001 23:59',freq='1h'),dtype=float)

   for i in np.arange(0,8761,1):

      def power(u):

        I=u
        diode=DataFrame(zeros(3898200).reshape((8760,445)),index=pd.date_range('1/1/2001 00:00','12/31/2001 23:59',freq='1h'),dtype=float)

        diode[i]=IL[i]-(Io[i]*(np.exp((v+(I*RS[i]))/a[i]-1)))-((v+(I*RS[i]))/Rsh[i])-I

        return diode

  I[i]=[opt.newton(power,2)for v in np.arange(0,44.5,0.1)]
  return I
I=elec()

我收到索引错误的错误:索引超出范围
我应该得到 8760*445 的 I 值

Traceback (most recent call last):
File "<ipython-input-176-18d774ef131a>", line 5, in <module>
elec()
File "<ipython-input-174-996ccd566a20>", line 18, in elec
I[i]=[opt.newton(power,2)for v in np.arange(0,44.5,0.1)]
File "C:\Python27\lib\site-packages\scipy\optimize\zeros.py", line 143, in newton
q0 = func(*((p0,) + args))
File "<ipython-input-174-996ccd566a20>", line 14, in power
diode_east[i]=IL_east[0][i]-(Io_east[0][i]*(np.exp((v+(I*RS_ref[i]))/a_east[0][i]-1)))-   ((v+(I*RS_ref[i]))/Rsh_east[0][i])-I
File "C:\Python27\lib\site-packages\pandas\core\series.py", line 613, in __getitem__
return self.index.get_value(self, key)
File "C:\Python27\lib\site-packages\pandas\tseries\index.py", line 1132, in get_value
return Index.get_value(self, series, key)
File "C:\Python27\lib\site-packages\pandas\core\index.py", line 769, in get_value
return tslib.get_value_box(series, key)
File "tslib.pyx", line 364, in pandas.tslib.get_value_box (pandas\tslib.c:8228)
File "tslib.pyx", line 379, in pandas.tslib.get_value_box (pandas\tslib.c:8075)
IndexError: index out of bounds

<type 'exceptions.IndexError'>
4

0 回答 0