nlopt icon indicating copy to clipboard operation
nlopt copied to clipboard

Additional data to non-linear constraints in Matlab

Open ostanley opened this issue 5 years ago • 0 comments

I would like to pass additional data to my constraint functions similar to f_data in the general reference. This is because I want constraints for multiple locations and this can be up to several hundred constraints. I would like to use Matlab if possible.

My approach was as follows, I defined a general function [x,g]=minimaxnloptconstraint_point(x,p) which takes in both x and the additional data, p.

Then I used a for loop to create a number of anonymous constraints:

point_func = {}
for p=1:size(coildata,1)
    point_func{p} = @(x) minimaxconstnlopt_point(x, p)
end

This issue is anonymous functions only allow for one output meaning I cannot supply a gradient to the optimizer. Functions cannot be defined in a loop unless they are anonymous. This leaves me at an impasse and I was wondering if anyone knew a way around this?

Thank you!

ostanley avatar Jun 11 '20 20:06 ostanley