optimization using lagrange multipliers
Afficher commentaires plus anciens
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
grad_Cx=diff(C,x);
grad_Cy=diff(C,y);
grad_Cz=diff(C,z);
%this is the g (constraint)-volume
grad_Vx=diff(V,x);
grad_Vy=diff(V,y);
grad_Vz=diff(V,z);
%equations to be solved
eqns=[grad_Cx==lambda*grad_Vx,grad_Cy==lambda*grad_Vy,grad_Cz==lambda*grad_Vz,x*y*z==V];
%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?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Partial Differential Equation Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!