8/7/2023 0 Comments Fmincon nonlinear constraintsIt's a very good approach for anyone else as well. I went down the road suggested by Kalvelagen. % Minimize function frbegin() subject to constraints. %FRBEGIN Function specified by rbeginner on stack overflow, X1=x(1) x2=x(2) x3=x(3) x4=x(4) x5=x(5) Ĭ= Īnd the function to minimize is just function z = frbegin(x) % Convert each constraint to equation that is <=0 when constraint is met. X(1) > 0 %handle this constraint by set lb(1)=0 % These are the constarints on function frbegin0(). %FRBEGINCON Constraints specified by rbeginner on stack overflow, I tried calling fmincon() with the function below for nonlcon, and had good results, for many random starting points. There are no equality constraints, so the value of 0 is returned for ceq. The first constraint, x(1)>0, is implemented by setting the lower bound for x(1) to 0, and function frbeginCon() takes care of the other constraints. It has an optional argument nonlcon, which is the name of a function that returns 2 arrays, c and ceq: the values of equations for the inequality constraints (if any), and the values of the equations for the equality constraints (if any). % Function frbeginner2() is to be minimized subject to constraints Here's what not to do: function Z = frbeginner2(x) It doesn't work well, probably because the discontinuities in the function cause problems for the built-in routine fmincon(). Each constraint is inverted, and 10^6 is added to the function return value if the inverse of a constraint is true. This is not elegant, but it would be easy. You could modify your function so that a large value is added each time a constraint is violated.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |