3 (define (myfunc x grad)
6 (vector-set! grad 0 0.0)
7 (vector-set! grad 1 (/ 0.5 (sqrt (vector-ref x 1))))))
8 (sqrt (vector-ref x 1)))
10 (define (myconstraint x grad a b)
11 (let ((x0 (vector-ref x 0)) (x1 (vector-ref x 1)))
14 (vector-set! grad 0 (* 3 a (expt (+ (* a x0) b) 2)))
15 (vector-set! grad 1 -1.0)))
16 (- (expt (+ (* a x0) b) 3) x1)))
18 (define opt (new-nlopt-opt NLOPT-LD-MMA 2))
19 (nlopt-opt-set-lower-bounds opt (vector (- (inf)) 0))
20 (nlopt-opt-set-min-objective opt myfunc)
21 (nlopt-opt-add-inequality-constraint opt (lambda (x grad)
22 (myconstraint x grad 2 0))
24 (nlopt-opt-add-inequality-constraint opt (lambda (x grad)
25 (myconstraint x grad -1 1))
27 (nlopt-opt-set-xtol-rel opt 1e-4)
28 (define x (nlopt-opt-optimize opt (vector 1.234 5.678)))
29 (define minf (nlopt-opt-last-optimum-value opt))
30 (define result (nlopt-opt-last-optimize-result opt))