optimization using lagrange multipliers

조회 수: 4(최근 30일)
Lal Deger 2021년 4월 3일
댓글: Lal Deger 2021년 4월 4일
I have a problem where I have to minimize cost of a container given by C = Sxy + 2Wz(x+y) and Volume=xyz where x,y are bottom dimensions and z the height of the box. S is the cost of material for the bottom per m^2 and W for the sides. For this I wrote the following code:
syms x y z S W lambda V
C=S*x*y+2*W*z*(x+y);
V=x*y*z;
%this is the f (function to be optimized)-cost
%this is the g (constraint)-volume
%equations to be solved
%solve
P=solve(eqns,[x y z lambda])
however in the answers I get (x,y,z,lambda)=(4W,4W,2S,1) and (0,0,0,0). The answer I should be getting is:
could anyone tell me what I am doing wrong?

댓글을 달려면 로그인하십시오.

채택된 답변

David Goodmanson 2021년 4월 4일
Hi Lal,
The problem is that you have V(x,y,z) = x*y*z as a function, but you do not define a fixed value for the volume. The code below uses V1 = x*y*z and later sets that to V.
% make variables positive to cut down to one solution
syms x y z S W lambda V1 V positive
C=S*x*y+2*W*z*(x+y);
V1=x*y*z;
%this is the f (function to be optimized)-cost
%this is the g (constraint)-volume
%equations to be solved
%solve
P=solve(eqns,[x y z lambda])
x0 = simplify(P.x)
y0 = simplify(P.y)
z0 = simplify(P.z)
lambda0 = simplify(P.lambda)
댓글 수: 1표시숨기기 없음
Lal Deger 2021년 4월 4일
Ohhh, I see thank you very much!!

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by