Constrained minimization in MATLAB

喜你入骨 提交于 2019-12-08 13:54:14

问题


I want to solve a constrained minimization problem and I am asking for some help on how to structure the code.

I understand that fmincon is what I should use by playing with the argument @mycon but I am struggling in adapting it to my case. Any suggestion would be extremely appreciated.

These are my files (a and b are predefined parameters):

  1. f1.m

    function [y1, y2, y3]=f1(x1, x2, a)
    ...
    end
    
  2. f2.m

    function w1=f2(x1, x2, y2, y3, b)
    ...
    end
    

Problem that I want to code:

min y1 w.r.t x1, x2
such that y1<=w1


回答1:


You could use fmincon as follows:

x = fmincon(@(x) f1(x(1), x(2), a), [x1_start x2_start], [], [], [], [], [], [], @(x) mycon(x(1), x(2), a, b));
x1 = x(1)
x2 = x(2)

with mycon defined as:

% C <= 0 and Ceq == 0
function [C, Ceq] = mycon(x1, x2, a, b)
    [y1, y2, y3] = f1(x1, x2, a);
    C = y1 - f2(x1, x2, y2, y3, b);
    Ceq = [];
end

and x1_start and x2_start the starting values for x1 and x2 in the iterative solver used by Matlab.

Please take a look at the matlab documentation and examples for more information.



来源:https://stackoverflow.com/questions/44464008/constrained-minimization-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!