2 external myfunc, myconstraint
5 double precision d1(2), d2(2)
6 double precision x(2), minf
11 call nlo_create(opt, NLOPT_LD_MMA, 2)
12 call nlo_get_lower_bounds(ires, opt, lb)
14 call nlo_set_lower_bounds(ires, opt, lb)
15 call nlo_set_min_objective(ires, opt, myfunc, 0)
19 call nlo_add_inequality_constraint(ires, opt, myconstraint, d1, 1.D-8)
22 call nlo_add_inequality_constraint(ires, opt, myconstraint, d2, 1.D-8)
24 call nlo_set_xtol_rel(ires, opt, 1.D-4)
28 call nlo_optimize(ires, opt, x, minf)
30 write(*,*) 'nlopt failed!'
33 write(*,*) 'found min at ', x(1), x(2)
34 write(*,*) 'min val = ', minf
41 subroutine myfunc(val, n, x, grad, need_gradient, f_data)
42 double precision val, x(n), grad(n)
43 integer n, need_gradient
44 if (need_gradient.ne.0) then
46 grad(2) = 0.5 / dsqrt(x(2))
51 subroutine myconstraint(val, n, x, grad, need_gradient, d)
53 double precision val, x(n), grad(n), d(2), a, b
56 if (need_gradient.ne.0) then
57 grad(1) = 3. * a * (a*x(1) + b)**2
60 val = (a*x(1) + b)**3 - x(2)