MATLAB中的约束最小化

MATLAB中的约束最小化

本文介绍了MATLAB中的约束最小化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想解决一个受约束的最小化问题,我正在寻求有关如何构建代码的帮助.

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

我知道fmincon是我应该通过处理参数@mycon来使用的,但是我正在努力使其适应我的情况.任何建议将不胜感激.

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.

这些是我的文件(ab是预定义的参数):

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

  1. f1.m

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

  • f2.m

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

  • 我要编码的问题:

    推荐答案

    您可以使用 fmincon 如下:

    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)
    

    ,其中mycon定义为:

    % 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
    

    x1_startx2_start在Matlab使用的迭代求解器中x1x2的起始值.

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

    请查看matlab文档和示例以获取更多信息.

    这篇关于MATLAB中的约束最小化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-29 03:15