Matlab 帮助 !! 江湖救急!!!!急急急!!谢谢!~

来源:百度知道 编辑:UC知道 时间:2024/05/14 17:30:27
求 y1=x1+x2
y2=3*x1^2-x1-5*x2^2+x2
x1的范围[0,8]
x2 [0,10]
求 y1^2+y2^2 的最小值
请附加程序/!~!~!~谢谢!~!~!~!~

【1】X=FMINCON(FUN,X0,A,B,Aeq,Beq,LB,UB) defines a set of lower and upper bounds on the design variables, X, so that a solution is found in the range LB <= X <= UB. Use empty matrices for LB and UB if no bounds exist. Set LB(i) = -Inf if X(i) is unbounded below; set UB(i) = Inf if X(i) is unbounded above.

function hhh
[x,fval]=fmincon(@myfun,[1;1],[],[],[],[],[0;0],[8;10])
function yy=myfun(x)
y(1)=x(1)+x(2)
y(2)=3*x(1)^2-x(1)-5*x(2)^2+x(2)
yy=y(1)^2+y(2)^2

运行结果:
x =
1.0e-003 *
0.6654
0.1000

fval =
9.0398e-007 %最小值啊

实际上,就是x1=0,x2=0,obj=0啦。

【2】可以用ezmesh看看
>> ezmesh('(x1+x2)^2+(3*x1^2-x1-5*x2^2+x2)^2',[0,8,0,10])