Hi, please look at the following sample code.
=================================================================
PRO Nlp_fcn2, x, iact, result, ierr
CASE iact OF
0 : result = (x[0] - 0.5)^2 + (x[1] - 0.5)^2
ENDCASE
ierr = 0
END
PRO Nlp_grad, x, iact, result
ans = IMSL_CONSTRAINED_NLP('Nlp_fcn2', 0, 2, MEQ = 0)
CASE iact OF
0:result = [ 2 * (x(0) - 2.), 2 * (x(1)-1.)]
1:result = [1., -2. ]
2:result = [-0.5*x(0), -2.0*x(1)]
ENDCASE
RETURN
END
PRO Nlp_fcn, x, iact, result, ierr
tmp1 = x(0)-2.
tmp2 = x(1) - 1.
CASE iact OF
0:result = tmp1^2 + tmp2^2
1:result = x(0) -2.*x(1) + 1.
2:result = -(x(0)^2)/4. - x(1)^2 + 1.
ENDCASE
ierr = 0
END
pro Test
ans2 = IMSL_CONSTRAINED_NLP('nlp_fcn', 2, 2, MEQ = 1, GRAD = 'nlp_grad')
PM, ans2, title='X with Analytic gradient'
end
=================================================================
If we remove "ans = IMSL_CONSTRAINED_NLP('Nlp_fcn2', 0, 2, MEQ = 0)" in the function Nlp_grad, Test would work; otherwise, it would fail, though the statement "ans = IMSL_CONSTRAINED_NLP('Nlp_fcn2', 0, 2, MEQ = 0)" is correct itself.
Any suggestion about how to fix this problem? Thanks!
|