Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from FuncDesigner import *
- x = oovar()
- f = sin(x) / x
- S = 10000000
- cons1 = [x>=0, x<=S]
- cons2 = [x>=-S, x<=0]
- cons3 = [x>=-S, x<=S]
- startPoint = {x:0.1}
- for cons in [cons1, cons2, cons3]:
- S = oosystem()
- r = S.minimize(f, startPoint, solver='interalg', fTol = 0.000000001, constraints = cons, iprint = 0)
- print('minimum value %e at point %e' %(r.ff, r(x)))
- # minimum value -2.172336e-01 at point 4.493409e+00 , 1.38 sec
- # minimum value -2.172336e-01 at point -4.493409e+00, 3.27 sec
- # minimum value -2.172336e-01 at point -4.493409e+00, 4.78 sec
- from numpy import linspace, argmin
- xx = linspace(-40, 40, 100000)
- y = f({x:xx})
- print('minimal value: % 0.7f' % min(y)) # minimal value: -0.2172336
- print('best point: % 0.7f' % xx[argmin(y)]) # best point: -4.4932449 (same to +4.4932449)
- from pylab import plot, show, grid
- plot(xx, y)
- grid('on')
- show()
- ------------------------- OpenOpt 0.37 -------------------------
- solver: interalg problem: unnamed type: NLP goal: minimum
- iter objFunVal
- 0 9.983e-01
- OpenOpt info: Solution with required tolerance 1.0e-09
- is guarantied (obtained precision: 1.0e-09)
- 104 -2.172e-01
- istop: 1000 (solution has been obtained)
- Solver: Time Elapsed = 1.39 CPU Time Elapsed = 1.38
- objFunValue: -0.21723363 (feasible, MaxResidual = 0)
- minimum value -2.172336e-01 at point 4.493409e+00
- ------------------------- OpenOpt 0.37 -------------------------
- solver: interalg problem: unnamed type: NLP goal: minimum
- iter objFunVal
- 0 9.983e-01
- OpenOpt info: Solution with required tolerance 1.0e-09
- is guarantied (obtained precision: 1.0e-09)
- 562 -2.172e-01
- istop: 1000 (solution has been obtained)
- Solver: Time Elapsed = 3.45 CPU Time Elapsed = 3.27
- objFunValue: -0.21723363 (feasible, MaxResidual = 0)
- minimum value -2.172336e-01 at point -4.493409e+00
- ------------------------- OpenOpt 0.37 -------------------------
- solver: interalg problem: unnamed type: NLP goal: minimum
- iter objFunVal
- 0 9.983e-01
- OpenOpt info: Solution with required tolerance 1.0e-09
- is guarantied (obtained precision: 1.0e-09)
- 563 -2.172e-01
- istop: 1000 (solution has been obtained)
- Solver: Time Elapsed = 4.78 CPU Time Elapsed = 4.78
- objFunValue: -0.21723363 (feasible, MaxResidual = 0)
- minimum value -2.172336e-01 at point -4.493409e+00
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement