0

I am using newton() function from the scipy to solve a particular non linear equation which works for a single values

 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 am trying to do the same for 8760 values of (I,Io,RS,a,Rsh) which are individual dataframes

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()

I am getting a error of index error:index out of bounds
I should get 8760*445 values of 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'>
vinoth mannan
  • 43
  • 1
  • 5
  • Can you please provide us with your full traceback? – Alex Koukoulas Mar 20 '14 at 20:20
  • sorry i have changed the name of the variable...Io_east[0] is a datarframe of 8760 values...like wise for other varaibles... – vinoth mannan Mar 20 '14 at 20:37
  • I'm finding it difficult to read your code due to either incorrect indentation or unconventional style. Is `power` being defined inside of a loop inside of another function? – askewchan Mar 21 '14 at 01:45
  • Also, in both of your lines that call `newton`, you're not using `v`, even though that's the variable of your list comprehension. Although I suppose you're relying on the scope of `v` to include the `power` function's scope. – askewchan Mar 21 '14 at 01:54
  • yes the power is defined within in the for loop...i have corrected the indentation – vinoth mannan Mar 21 '14 at 06:43

0 Answers0