Advertisement

# Untitled

Feb 21st, 2012
96
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from FuncDesigner import *
2. x = oovar()
3. f = sin(x + 5000000)/(x+5000000)
4. S = 10000000
5. cons = [x>=0, x<=S]
6. startPoint = {x:0.1}
7. S = oosystem()
8. r = S.minimize(f, startPoint, solver='interalg', fTol = 0.000000001, constraints = cons, iprint = -1)
9. print('value %e  at point %e' %(r.ff, r(x)))
10. # obvious upper bound:
11. # sin(x+ 5000000)<=1, x+5000000 >= 5000000, thus sin(x + 5000000)/(x+5000000) <= 1.0/5000000
12. # in the same way sin(x + 5000000)/(x+5000000) >= -1.0/5000000
13. print(1.0/5000000 - abs(r.ff))
14.
15. # maximization:
16. #value 1.994124e-07  at point 7.317041e+03
17. #[  5.87598607e-10]
18. # minimization:
19. #value -1.991849e-07  at point 1.143669e+03
20. #[  8.15073300e-10]
21. # distances to analitically calculated guaranteed bounds less than 1e-9,
22. # and distance to exact optimum is even less
Advertisement
RAW Paste Data Copied
Advertisement