Matlab(fmincon):警告: 矩阵接近奇异值,或者缩放错误。结果可能不准确。RCOND = 2.156571e-16。

This warning may be displayed if for certain values of input parameters “x”, the objective function returns a NaN value (not a number). Because of this, FMINCON is unable to determine the gradient of the objective function and throws the warning above.
To avoid the warning, you may need to modify your objective function to return non-NaN values for inputs of this type. There are also known limitations with the Active-Set algorithm in that in certain intermediate iterations it may choose a value of “x” that violates the constraints. This can pose a problem if the objective function is not defined (returns NaN) for values of “x” in which the constraints are invalid.
If this is relevant to your application, as workarounds you can either generalize the objective function to handle such values of “x” or use the Interior-Point algorithm which does not have this limitation.

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用 MATLAB 的 fmincon 函数进行求解,代码如下: ```MATLAB % 定义目标函数 z fun = @(x) -0.7 * x(1) * x(2) * x(3) + x(4); % 定义不等式约束条件 nonlinearConstr = @(x) deal([], -x(2) * 51.333 + 5042.222 * x(1) - 51.333); % 定义变量的取值范围 lb = [0, 20, 0, -Inf]; ub = [7000, 60, Inf, Inf]; % 定义初始值 x0 = [3500, 40, 1.0, 0]; % 使用 fmincon 函数求解最小值 options = optimoptions('fmincon', 'Display', 'iter'); [x, fval] = fmincon(fun, x0, [], [], [], [], lb, ub, nonlinearConstr, options); % 输出结果 fprintf('最大值为 %.4f,取值为 x = %.4f, p = %.4f, q = %.4f, k = %.4f\n', -fval, x(1), x(2), x(3), x(4)); ``` 解释一下代码: - 第一行定义了目标函数 z,其中 x(1)、x(2)、x(3)、x(4) 对应于 q、p、k、-x-48250。 - 第三行定义了不等式约束条件。由于 fmincon 函数只能求解小于等于零的约束条件,因此需要将等式约束 q-5042.222p+51.333=0 转化为不等式约束 -x(2) * 51.333 + 5042.222 * x(1) - 51.333 <= 0。 - 第五行和第六行分别定义了变量的取值范围 lb 和 ub。注意,第四个变量 x(4) 没有上下界限制,因此用 Inf 表示正无穷和负无穷。 - 第八行定义了初始值 x0。 - 第十行使用 fmincon 函数求解最小值,其中 nonlinearConstr 参数指定了不等式约束条件,options 参数可以设置优化过程的一些选项,如 Display 表示每次迭代的输出信息。 - 最后一行输出结果,注意要将目标函数取负数才是最大值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值