Advertisement
mikofski

benchtest_newton_numpy.py

Feb 3rd, 2018
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. #! PYTHONPATH=/Users/markmikofski/Projects/pvlib-python:/Users/markmikofski/Projects/scipy/scipy/optimize ipython
  2.  
  3. from numpy import sin as np_sin, exp as np_exp, asarray, random
  4. import zeros
  5.  
  6. NUM_OF_IRRAD = 100000
  7. IL = random.rand(NUM_OF_IRRAD) + 6.0
  8.  
  9.  
  10. def f_solarcell(i, v, il, io, rs, rsh, vt):
  11.     vd = v + i * rs
  12.     return il - io * (np_exp(vd / vt) - 1.0) - vd / rsh - i
  13.  
  14.  
  15. def fprime(i, v, il, io, rs, rsh, vt):
  16.     return -io * np_exp((v + i * rs) / vt) * rs / vt - rs / rsh - 1
  17.  
  18.  
  19. def fprime2(i, v, il, io, rs, rsh, vt):
  20.     return -io * np_exp((v + i * rs) / vt) * (rs / vt)**2
  21.  
  22.  
  23. def bench_newton_array():
  24.     """test newton with array"""
  25.     return zeros.newton(f_solarcell, 7.0, fprime,
  26.                         (5.25, IL, 1e-09, 0.004, 10, 0.27456))
  27.  
  28.  
  29. def bench_halley_array():
  30.     """test newton with array"""
  31.     return zeros.newton(f_solarcell, 7.0, fprime,
  32.                         (5.25, IL, 1e-09, 0.004, 10, 0.27456),
  33.                         fprime2=fprime2)
  34.  
  35.  
  36. def bench_secant_array():
  37.     """test newton with array"""
  38.     return zeros.newton(f_solarcell, 7.0,
  39.                         args=(5.25, IL, 1e-09, 0.004, 10, 0.27456))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement