Problem 4.18

advertisement
Problem 4.18
Here the objective function (we minimize minus the area) is coded so that parameters
can be passed to it:
function [f,gradf]=objfun(x,l,dm)
a=1.5;b=2.5;L=4;
f=-(x(1)*x(2)+x(2)*x(3)+x(3)*x(4)+x(4)*x(1))/2;
gradf=-[x(2)+x(4);x(1)+x(3);x(2)+x(4);x(3)+x(1)]/2;
Analogously for the constraint function:
function [c,ceq]=confun(x,l,dm)
a=1.5;b=2.5;
c1=-x(1)*x(2)+sqrt(a^2*x(2)^2+b^2*x(1)^2)+dm*sqrt(x(1)^2+x(2)^2);
c2=-x(3)*x(2)+sqrt(a^2*x(2)^2+b^2*x(3)^2)+dm*sqrt(x(3)^2+x(2)^2);
c3=-x(3)*x(4)+sqrt(a^2*x(4)^2+b^2*x(3)^2)+dm*sqrt(x(3)^2+x(4)^2);
c4=-x(1)*x(4)+sqrt(a^2*x(4)^2+b^2*x(1)^2)+dm*sqrt(x(1)^2+x(4)^2);
c=[c1;c2;c3;c4]; ceq=sqrt(x(1)^2+x(2)^2)+sqrt(x(3)^2+x(2)^2)+ ...
sqrt(x(3)^2+x(4)^2)+sqrt(x(1)^2+x(4)^2)-l;
The computations are carried out in a script file in which the parameters are adjusted:
dm=0.3;l=20;
L=4;a=1.5;b=2.5;
options = optimset(’GradObj’,’on’);
ub=[L;L;L;L];lb=[a;a;a;a];
x0=[.5*(a+L);.5*(b+L);.5*(a+L);.5*(b+L)];
[xopt,fopt] = fmincon(’objfun’,x0,[],[],[],[],lb,ub,’confun’,options,l,dm);
xopt,fopt=-fopt
Executing this script gives the answer for (a):
xopt =
3.53553392624771
3.53553369727462
3.53553391780004
3.53553408242880
fopt =
25.00000000007151
The answer for (b) is found after setting dm = 0.4:
1
xopt =
3.53552768715265
3.53553946871407
3.53552768533629
3.53554078900112
fopt =
25.00000002280872
Note that (a) and (b) have the same optimal solutions. After setting dm = 0.1 and l = 17
we obtain the answer to (c),
xopt =
2.86127669017733
3.14254605411723
2.86127669017733
3.14254605411723
fopt =
17.98338754490877
which is different from the answers found in (a) and (b).
In each case we plot the lakes’s bounding ellipse, the boundary of the square area, and
the location of the fence via
s1=xopt(1);s2=xopt(2);s3=xopt(3);s4=xopt(4);
t=linspace(0,2*pi,100);xe=a*cos(t);ye=b*sin(t);
plot(xe,ye,’k’,[L 0 -L 0 L],[0 L 0 -L 0],’k’,[s1 0 -s3 0 s1],[0 s2 0 -s4 0],’k’)
axis square
4
4
(a)
3
4
(b)
3
2
2
2
1
1
1
0
0
0
−1
−1
−1
−2
−2
−2
−3
−3
−3
−4
−4
−2
0
2
−4
4 −4
−2
0
2
2
(c)
3
4
−4
−4
−2
0
2
4
Download