text: # How do I code for optimization of max volume of box?
  
  4 ビュー (過去 30 日間)
  Nishaal 2023 年 5 月 26 日
  
  I want to perform an optimization to find the max volume for the box with the formulas V=w*h*l and w+h+l<=460. However, I have difficulties trying to make a line for optimization after the partial differentiation. This is what I have so far
  syms V W H L
  % the formula for volume of a box is;
  V=W*H*L
  % since the total sum of the width, W, height, H and length, L is equal to
  % or lesser than 460cm;
  W+H+L<=460
  %rearrange for L in terms of W and H;
  L=isolate(W+H+L==460,L)
  %subsitute the formula for L into the formula for the volume of the box;
  V=subs(V,lhs(L),rhs(L))
  expand(V)
  % to find maximum volume, differentiate V to the respect of W and H, and let dV/dW=0 and dV/dH=0;
  dVdW=diff(V,W)==0
  dVdH=diff(V,H)==0
  
  サインインしてコメントする。
  
  ### 回答 (1 件)
  
  John D'Errico 2023 年 5 月 26 日
  It would arguably be a good time to learn about something called Lagrange multipliers. They allow you to build constraints into an optimization problem. But I would also guess they are beyond your wage grade for now, so simplest is to do as you did, that is, assume the solution lies on the constraint plane. In that case, you essentially eliminated the variable L from the problem.
  syms V W H L
  % the formula for volume of a box is;
  V=W*H*L
  V =
  % the constraint plane
  con = W+H+L == 460;
  Lsol = solve(con,L)
  Lsol =
  V = subs(V,L,Lsol)
  V =
  L is now gone from this problem, though you will need it later. But now differentiate, and solve. We can differentiate by computing the gradient vector.
  ans =
  and then apply solve.
  Finally, recover the value of L. Be careful though, because if any of those variables were less than zero in the final solution, it would suggest you have a problem.
  ##### 2 件のコメントなしを表示なしを非表示
  Nishaal 2023 年 5 月 26 日
  is there a reason it says
  struct with fields:
  H: [4×1 sym]
  W: [4×1 sym]
  Torsten 2023 年 5 月 26 日
  
  You will have to exclude non-positive side lengths by looking closer at the solution.
  The "solve" command will also give minimum instead of maximum volume solutions.
  HWsol.H
  HWsol.W
  to your code and analyze the 4 solution pairs for H and W.
  
  サインインしてコメントする。
  
  ### カテゴリ
  
  Help Center および File ExchangeQuadratic Programming and Cone Programming についてさらに検索
  
  R2023a
  
  ### Community Treasure Hunt
  
  Find the treasures in MATLAB Central and discover how the community can help you!
  
  Start Hunting!
  
  Translated by
metadata: {"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}