![]() ![]() ![]() Thank you Torabi and especially rosewc for help. Setting the Initial conditions x0.x1 = 0.01 Looking at the problem again to check showproblem(prob1) Setting constraints constr1 = x1 - (x4*x3) - x2 <=0 Ĭonstr3 = (x4*(x3))*(x2-((1-x3)/2))-(x1*(x2-x1+(x4*x3)))<=0 There are even more constraints used in semi-infinite programming see fseminf Problem Formulation and Algorithm. X5 = optimvar("x5","LowerBound",0,"UpperBound",1) Ĭreating an objective function edit functionĬreating optimizing expression obj = Objective function prob1.Objective = obj This is how I did itĬreating an empty problem prob1 = optimproblemĭefining Optimization variables with bounds x1 = optimvar("x1", "LowerBound",0) Consult the fmincon function reference page. It's a very good approach for anyone else as well. For a problem with a nonlinear objective function and a nonlinear constraint, generally you use the fmincon solver. I went down the road suggested by Kalvelagen. ![]() % Minimize function frbegin() subject to constraints. %FRBEGIN Function specified by rbeginner on stack overflow, Each time fmincon can't satisfy a specific condition (e.g., x (N)-7.6Tol ), the number N of nonlinear constraints should be updated (increased). This evaluation is wasteful when you use the same calculation. 1 I am trying to use fmincon in a while loop such that until the while condition is not satisfied, fmincon must be executed. 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) Solvers such as fmincon evaluate the objective and nonlinear constraint functions separately. % 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 |