# 线性函数的回归问题

min F(x)  subject to:  A*x <= b, Aeq*x = beq  线性约束条件
x               c(x) <= 0, ceq(x) = 0  非线性约束条件
lb<= x <= ub        约束边界

x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)

Fmin=x1^2+4*x2^2-3*x2*x3+0.5*x3

3*x1+2*x2+x3<=12
2*x1+3*x2-x3<=15
-10<=x1<=10
-10<=x2<=10
-10<=x3<=10
function f=myfun2(x)
f=x(1)^2+4*x(2)^2-3*x(2)*x(3)+0.5*x(3);
MATLAB主程序：
clc
clear all
A=[3,2,1;2,3,-1];
b=[12;15];
Aeq=[];
beq=[];
lb=[-10;-10;-10];
ub=[10;10;10];
x= fmincon(@(x) myfun2(x),[1;1;1],A,b,Aeq,beq,lb,ub);

x =
-1.6500
3.4750
10.0000
>> f=x(1)^2+4*x(2)^2-3*x(2)*x(3)+0.5*x(3)
f =
-48.2250

Fmin=m1*x1^2+m2*x2^2
n/x1-x2<=0;

function f = myfun(x,m)
f = m(1)*x(1)^2 + m(2)*x(2)^2;
function [c,ceq] = mycon(x,n)
c = n/x(1) - x(2);
ceq = [];
MATLAB主程序：
clc
clear all
m = [1,2]; n= 1.5;
options = optimoptions('fmincon','Algorithm','interior-point');
A=[];b=[];Aeq=[];beq=[];lb=[];ub=[];
x = fmincon(@(x) myfun(x,a),[1;2],A,b,Aeq,beq,lb,ub,@(x) mycon(x,n),options)

x =
1.4565
1.0299