Advertisement
Dmitrey15

Untitled

May 24th, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. from numpy import *
  2. from openopt import NSP
  3.  
  4. N = 10
  5.  
  6. def objFun(x):
  7.     r = 0.0
  8.     for j in range(N):
  9.         for i in range(N):
  10.             r += abs(x[i]) * (cos(i) + sin(j) + 15)
  11.     return r
  12.  
  13. x0 = cos(1+asfarray(range(N)))
  14.  
  15. p = NSP(objFun, x0, maxFunEvals = 1e7, xtol = 1e-8)
  16.  
  17. r = p.solve('ralg', iprint = 10, fEnough = 0.01)
  18.  
  19. # intel Atom 1.66 GHz:
  20. # 20.6 sec in CPython 2.7
  21. # 9.9 sec in PyPy 1.8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement