Can you please elaborate more on how to do that? I have 11 variables that define my constraints and one of those variables is the one to be minimized using fmincon. Each of these variables can be a vector and i want to use fmincon on all elements of the vectors at the same time (vectorized)
I have 11 variables that define my constraints and one of those variables is the one to be minimized using fmincon.
Your objective and constraints must be written as functions that take a single vector containing all of your unknowns as an input argument. That way, all functions have access to all variables, whether they need them all or not.
In my objective and nonlincon functions i passed a matrix x where x contains a vector for each variable of my 11 variables but the runtime did not change.
where in_spec are given by user and aaSynFoldedPmosOL is a function that calculates the constraints i have not yet given a grradient function for either nonlincon or obj functions i was using finite difference step size options to control the gradient.
my function is highly nonlinear so what kind of gradient should i provide ?
Now that we have a clearer view of your problem, it is not clear what you were hoping to "vectorize". Vectorization means that you try to process N separate tasks as a single task. But you do not appear to have N separate optimization jobs - your constraints depend on all X(i,j) simultaneously.
By vectorized i mean i want fmjncon to make use of my vectorized aaSynFolded function and my X matrix which has a number of design points row and 11 variables column. I want to run fmincon on each point of my matrix simultaneously. I tried to pass my X matrix as a starting point for fmincon but it give me error: supplied objective function must return scalar value
First of all thank you for your help. I tried your solution and what it did is it made function evaluations of the size of my input matrix every iterations which took a lot of time and memory. I was thinking about your first suggestion to provide my own derivative calculation for obj and nonlincon but i do not know how. Do i need to provide the derivative of my obj function which is just a vector of my input matrix with respect to every other variable in my matrix? And if that's correct does it mean i need to get x11 as a function of all other variables from my synfolded function?
You may want to consider first, though, whether this "vectorization" you are pursuing is worthwhile. You haven't told us how many sub-problems you are trying to simultaneously solve. I think you would have to have at least several hundred, each of them fairly simple to solve individually, before you would see a benefit.
And if that's correct does it mean i need to get x11 as a function of all other variables from my synfolded function?
No, all of your x(i,j) are to be viewed as independent variables.
Thank you for the documentation you provided. I am still facing a problem unlike the documentation my obj and nonlincon constraints are not a direct function of my 11 variables so i do not know how to provide the gradient. As for the reason i am pursuing vectorization is that my input is many points and i wanted to run an optimization function on each of my input points simultaneously but fmincon can not do that so instead i tried to provide the gradients. All of that is just to try and get the least run time possible. Thank you again for your patience.
My input points can be up to million each of 11 design variables so it is a large space. My function is not an explicit one it is a simulation function so i do not know how to provide gradient for it.
I'm not sure, i think my variables and constraints are related in a non linear fashion, as i said it is based on simulations. Does that mean i can not provide my own gradients to the function?
Then maybe the function is differentiable (even if you cannot prove it). Or, you got lucky and the iterations never landed near a point of non-differentiability.
It is still an open question, though, whether vectorization is a worthwhile option for you. Can you even run the simulation in a vectorized fashion? I.e., can you run a batch of simulations for multiple parameter sets more efficiently than just doing a loop over the parameter sets?
If an analytical calculation is too difficult, you can also try your own vectorized finite difference method to find the Jacobian of your simulation function. From that, it should be easier to find the total derivative of your objective using the chain rule.