yunzhongcheng
2009-04-19, 17:53
function [c,ceq]=mycon(x)
c=[sqrt((x(1)-30)^2+(x(2)-8)^2)-35;
sqrt((x(1)-6)^2+(x(2)-11)^2)-35;
sqrt((x(1)-12)^2+(x(2)-65)^2)-35;
sqrt((x(1)-56)^2+(x(2)-28)^2)-35;
sqrt((x(1)-45)^2+(x(2)-39)^2)-35];
ceq=[];
function f=myfun(x)
f=200*sqrt((x(1)-30)^2+(x(2)-8)^2)
+300*sqrt((x(1)-6)^2+(x(2)-11)^2)
+250*sqrt((x(1)-12)^2+(x(2)-65)^2)
+100*sqrt((x(1)-56)^2+(x(2)-28)^2)
+150*sqrt((x(1)-45)^2+(x(2)-39)^2);
clear
x0=[31,36.5];
lb=[56,65];
ub=[6,8];
[x,fval]=fmincon(@fun,x0,[],[],[],[],lb,ub,@mycon)
运行结果为:
x =
31.0000 36.5000
fval =
[]
程序错哪了,哪位知道,谢谢了
c=[sqrt((x(1)-30)^2+(x(2)-8)^2)-35;
sqrt((x(1)-6)^2+(x(2)-11)^2)-35;
sqrt((x(1)-12)^2+(x(2)-65)^2)-35;
sqrt((x(1)-56)^2+(x(2)-28)^2)-35;
sqrt((x(1)-45)^2+(x(2)-39)^2)-35];
ceq=[];
function f=myfun(x)
f=200*sqrt((x(1)-30)^2+(x(2)-8)^2)
+300*sqrt((x(1)-6)^2+(x(2)-11)^2)
+250*sqrt((x(1)-12)^2+(x(2)-65)^2)
+100*sqrt((x(1)-56)^2+(x(2)-28)^2)
+150*sqrt((x(1)-45)^2+(x(2)-39)^2);
clear
x0=[31,36.5];
lb=[56,65];
ub=[6,8];
[x,fval]=fmincon(@fun,x0,[],[],[],[],lb,ub,@mycon)
运行结果为:
x =
31.0000 36.5000
fval =
[]
程序错哪了,哪位知道,谢谢了