matlab 多个等式约束,求极值
发布网友
发布时间:2023-10-20 08:20
我来回答
共2个回答
热心网友
时间:2024-11-08 21:26
做个测试,希望有所帮助。
代码
function main()
% By lyqmath
clc; clear all; close all;
x0 = [1;0;1];
options = optimset('Algorithm','active-set');
[x,fval] = fmincon(@myfun,x0,[],[],[],[],[],[],...
@mycon,options)
function f = myfun(x)
f = x(1)^2 + x(2)^2 + x(3)^2;
function [c,ceq] = mycon(x)
c = 0;
ceq = [cos(x(1))+x(2)
x(2)+x(3)*x(3)];
结果
Local minimum possible. Constraints satisfied.
fmincon stopped because the predicted change in the objective function
is less than the default value of the function tolerance and constraints
are satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
Active inequalities (to within options.TolCon = 1e-06):
lower upper ineqlin ineqnonlin
1
x =
0.8758
-0.6403
0.8002
fval =
1.8175
>>
热心网友
时间:2024-11-08 21:27
这属于一种求解带等式约束非线性规划问题全局最优解的方法,matlab有现成函数,自己查吧。