Passing a variable constraint to fmincon
2 views (last 30 days)
I am using the 'fmincon' solver for optimizing a function that takes array of inputs. The optimization function is FUN = @(x)((sqrt((x(1) - a)^2 + (x(2) - b)^2) + sqrt((x(1) - c)^2 + (x(2) - d)^2))^2 - (y(nn))^2)^2. Note that y(nn) changes with 'nn'.
Currently, I am defining 'FUN' in a for loop so I can pass a scalar 'y'. Similary, the constraint function for 'FUN', i.e. c = sqrt((x(1)- h).^2 + (x(2) - g).^2)- y(nn) also change with 'nn'. However, I cannot call c(x,y(nn)) inside fimincon and neither can I define c(x) inside the for loop with a fixed value of y(nn). So, I would like to ask:
- Is there any efficient way to pass the vector input 'y' to fmincon without defining FUN in a for loop?
- How do I pass a vector argument to c(x) in addition to 'x'?
Matt J on 18 May 2023
Edited: Matt J on 18 May 2023
I think this is what you mean,
FUN = @(x)((sqrt((x(1) - a)^2 + (x(2) - b)^2) + sqrt((x(1) - c)^2 + (x(2) - d)^2))^2 - (ynn)^2)^2
c = sqrt((x(1)- h).^2 + (x(2) - g).^2)- y;