sách gpt4 ai đã đi

Tối ưu hóa Matlab

In lại 作者:行者123 更新时间:2023-12-03 17:31:01 29 4
mua khóa gpt4 Nike

您好,我正在使用 Matlab 优化求解器,但程序有问题。我收到此消息 fmincon 已停止,因为目标函数值小于目标函数限制的默认值,并且约束满足在约束容差的默认值范围内。我也收到以下消息。警告:矩阵接近奇异或严重缩放。程序发出的值不正确。我需要最小 x 和 z。功能如下

  x*sqrt((16+y^2))+z*sqrt((1+y^2)). 

任何帮助将不胜感激。
跟随约束如下。
20*sqrt((16+y^2))-100000*y*x
80*sqrt((1+y^2))-100000y*z
1<=y
y<=3
(x,z)transpose >0

function [c,ceq]=confun(x)
c=[(20*((16+x(2)^2)^.5))-100000*(x(2)*x(3)); (80*1+x(2)^2)^.5)-100000*x(2)*x(3); -x(2)+3; -x(2)+1; x(3)>0; x(1)>0];
ceq=[];

function f=obj(x)
f=x(1)*((16+x(2)^2)^.5)+x(3)*((1+x(2)^2)^.5);

x0=[1;1;1];
[x,fval]=fmincon(@obj,x0,[],[],[],[],[],[],@confun)

1 Câu trả lời

您的主要问题是您将二进制测试返回 1在您的非线性约束函数中取得成功,预计 <= 0关于成功。

您的第二个问题是将线性约束置于非线性约束函数中。这“有效”,但 fmincon 可以用已知的线性约束做一些技巧,而你没有得到好处。

下面是显示结果的可运行示例

  • 被破坏的纯非线性约束
  • 固定的纯非线性约束
  • 组合线性/非线性约束

  • Mã số:
    function example()
    % initial conditions
    x0=[1;1;1];

    % linear constraint system (Ax <= b)
    A = [0 -1 0;
    0 1 0;
    -1 0 0;
    0 0 -1];
    b = [-1 3 0 0]';

    display('Run with broken nonlinear-only constraints');
    [x,fval]=fmincon(@obj,x0,[],[],[],[],[],[],@conBroken)
    display('Run with fixed nonlinear-only constraints');
    [x,fval]=fmincon(@obj,x0,[],[],[],[],[],[],@conFixed)
    display('Run with linear/nonlinear constraints');
    [x,fval]=fmincon(@obj,x0,A,b,[],[],[],[],@conNonlin)

    % oops, x(...)>0 is 1 upon success
    function [c,ceq]=conBroken(x)
    c=[(20*((16+x(2)^2)^.5))-100000*(x(2)*x(3)); (80*1+x(2)^2)^.5-100000*x(2)*x(3); -x(2)+3; -x(2)+1; x(3)>0; x(1)>0];
    ceq=[];

    % good, -x(...) <= 0 when x>0
    function [c,ceq]=conFixed(x)
    c=[(20*((16+x(2)^2)^.5))-100000*(x(2)*x(3)); (80*1+x(2)^2)^.5-100000*x(2)*x(3); -x(2)+3; -x(2)+1; -x(3); -x(1)];
    ceq=[];

    % moved linear constraints to where they should be
    function [c,ceq]=conNonlin(x)
    c=[(20*((16+x(2)^2)^.5))-100000*(x(2)*x(3)); (80*1+x(2)^2)^.5-100000*x(2)*x(3);];
    ceq=[];

    % objective function
    function f=obj(x)
    f=x(1)*((16+x(2)^2)^.5)+x(3)*((1+x(2)^2)^.5);

    这给出了以下结果:

    使用已损坏的纯非线性约束运行 -- 违反 x>0 约束
    Solver stopped prematurely.

    fmincon stopped because it exceeded the function evaluation limit,
    options.MaxFunEvals = 3000 (the default value).

    x =
    -23.3480
    6.3806
    0.0470

    fval =
    -175.5250

    使用固定的纯非线性约束运行 ——朝着正确的方向缓慢前进
    Solver stopped prematurely.

    fmincon stopped because it exceeded the function evaluation limit,
    options.MaxFunEvals = 3000 (the default value).

    x =
    0.1893
    1.8200
    0.5598

    fval =
    1.9947

    使用线性/非线性约束运行 ——有效!
    Local minimum found that satisfies the constraints.

    Optimization completed because the objective function is non-decreasing in
    feasible directions, to within the default value of the function tolerance, and
    constraints are satisfied to within the default value of the constraint tolerance.

    x =
    0.0000
    1.9993
    0.0004

    fval =
    0.0010

    教训是:始终单独提供线性约束,这样奇迹就会发生。

    关于Matlab 优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34033665/

    29 4 0
    Bài viết được đề xuất: unix - 为什么不使用查找优化?
    Bài viết được đề xuất: performance - Netlogo:优化补丁中乌龟邻居的计算
    Bài viết được đề xuất: key - Không thể thêm khóa từ keys.gnupg.net
    Bài viết được đề xuất: optimization - SOCP : minimize sum of euclidean norms
    行者123
    Hồ sơ cá nhân

    Tôi là một lập trình viên xuất sắc, rất giỏi!

    Nhận phiếu giảm giá Didi Taxi miễn phí
    Mã giảm giá Didi Taxi
    Giấy chứng nhận ICP Bắc Kinh số 000000
    Hợp tác quảng cáo: 1813099741@qq.com 6ren.com