Is it possible to include a 'for loop' in a constraint file for optimization using fmincon solver?
Show older comments
I am solving a multiperiod optimization problem using fmincon solver.Some of the constraints are non linear.The constraints are to be repeated for all periods.Is it possible to repeat the constraints for all periods by including a for loop in the mfile for constraints?
4 Comments
Alan Weiss
on 5 Feb 2018
I am afraid that I do not understand your question. A nonlinear constraint function is a MATLAB function. It can have any valid MATLAB commands, including if, while, for, or anything else.
But I think that is not really what you are asking. So can you please rephrase?
Alan Weiss
MATLAB mathematical toolbox documentation
Sukanya J Nair
on 6 Feb 2018
Walter Roberson
on 6 Feb 2018
for i = 1:12; ceq(i) = P(i)-a*h(i)*s(i); end
However it would make more sense to vectorize:
ceq = P - a .* h .* s;
Sukanya J Nair
on 6 Feb 2018
Answers (0)
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!