You asked the same question in an issue, and I answered you there:
https://github.com/stevengj/nlopt/issues/296
<https://github.com/stevengj/nlopt/issues/296>
In short, you should wrap an "if (grad) { ..... }" block around your gradient
calculation.
> On Sep 24, 2019, at 7:09 PM, xiaohai wang <[email protected]>
> wrote:
>
> Hi guys,
> i have a problem with NLopt SLSQP in C,
> my compiler throws out a exception after 2 iterations of optimization in my
> object function, at my computation of gradient, it said:
>
> Exception thrown: write access violation.
> grad was nullptr.
>
>
> the problem is , i used the same code on matlab , it works fine, but the
> results of cost function under the initialized value between matlab and c are
> not the same, the gradient as well,
> the difference is about 1e-5, and the difference between gradient are huge,
> could that caused my exception?
>
> i noticed that the difference from xAll(solution of A*x + B*u = x_dot, it is
> my state equation) started at 200th row(xAll should be 2500x5), and the
> difference is about 1e-12 to 1e-15
> did anyone know why?
>
> attached is my c-code , could anyone help me
>
> <test.c>_______________________________________________
> NLopt-discuss mailing list
> [email protected] <mailto:[email protected]>
> http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss
> <http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss>
_______________________________________________
NLopt-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss