使用数据帧的newton raphson方法

时间:2014-03-20 20:18:49

标签: python scipy dataframe nonlinear-functions nonlinear-optimization

我正在使用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的值

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'>

0 个答案:

没有答案