function myfmincon()
clc
options = optimset('Algorithm','interior-point');
A=[-1,1;1,0];
B=[10;10];
Aeq=[];
Beq=[];
LB=[];
UB=[];
x0=[0;0];
[x Fval]= fmincon(@(x) myfun(x),x0,A,B,Aeq,Beq,LB,UB,@(x) mycon(x),options);
disp('最小值Fval为')
Fval
disp('规划解x为')
x
function y = myfun(x)
y = 4*(x(1)-5)^2+(x(2)-6)^2;
function [c,ceq] = mycon(x)
c =-(x(1)^2+x(2)^2-64);
ceq = [];
结果为:
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 were satisfied to within the default value of the constraint tolerance.
最小值Fval为
Fval =
0.0516
规划解x为
x =
5.0427
6.2105
>>