# optimization using lagrange multipliers

5 ビュー (過去 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