chiark / gitweb /
Import nlopt_2.4.2+dfsg.orig.tar.gz
[nlopt.git] / test / test_std.py
1 #!/usr/bin/env python
2
3 import nlopt
4 import numpy as np
5
6 print ('nlopt version='+nlopt.__version__)
7
8 def f(x, grad):
9     F=x[0]
10     L=x[1]
11     E=x[2]
12     I=x[3]
13     D=F*L**3/(3.*E*I)
14     return D
15
16 n = 4
17 opt = nlopt.opt(nlopt.LN_COBYLA, n)
18 opt.set_min_objective(f)
19 lb = np.array([40., 50., 30e3, 1.])
20 ub = np.array([60., 60., 40e3, 10.])
21 x = (lb+ub)/2.
22 opt.set_lower_bounds(lb)
23 opt.set_upper_bounds(ub)
24 opt.set_xtol_rel(1e-3)
25 opt.set_ftol_rel(1e-3)
26 xopt = opt.optimize(x)
27
28 opt_val = opt.last_optimum_value()
29 result = opt.last_optimize_result()
30 print ('opt_result='+str(result))
31 print ('optimizer='+str(xopt))
32 print ('opt_val='+str(opt_val))