# Minimize the Surface Area of a Box with a Given Volume # Mark Collins & Carlo De Guzman # Math 253 Sec 201 Fall 2014 # Instructor: Yasskin # restart; with(Maplets[Tools]):with(Maplets[Elements]):with(plots):with(ArrayTools): StartEngine(): randomize(): Ls:=[2,4,6,8,10,12,16,20,30,32,36,50,54]: randL:=rand(1..nops(Ls)): NewProblem:=proc() global l,w,h,Lvalue,Wvalue,Hvalue,A1value,V1value,A1,V1,gradA,gradV,LEs,dimsarray; Lvalue:=Ls[randL()]; Wvalue:=Lvalue; Hvalue:=Lvalue/2; A1value:=Lvalue*Wvalue+2*(Lvalue+Wvalue)*Hvalue; V1value:=Lvalue*Wvalue*Hvalue; A1:=l*w+2*(l+w)*h; V1:=l*w*h; gradA:=[w+2*h,l+2*h,2*w+2*l]; gradV:=[w*h,l*h,l*w]; LEs:=[gradA[1]=lambda*gradV[1],gradA[2]=lambda*gradV[2],gradA[3]=lambda*gradV[3]]; dimsarray:=[Lvalue,Wvalue,Hvalue]; Set(TBProb=sprintf(" Minimize the surface area of a rectangular box without a lid whose volume is %a.",V1value)); Set(LeqV0(caption)=sprintf("= %a",V1value)); Set(TFA=""); Set(TFg=""); Set(TFgradA=""); Set(TFgradV=""); Set(TFLE_l=""); Set(TFLE_w=""); Set(TFLE_h=""); Set(TFl=""); Set(TFw=""); Set(TFh=""); Set(TFA1value=""); Set(MRA=""); Set(MRg=""); Set(MRgradA=""); Set(MRgradV=""); Set(MRLE=""); Set(MRlwh=""); Set(MRA1value=""); Set(reply=""); end proc: HintA:=proc() Set(reply="Find the area of the base, then the area of each of the sides. Add those together and simplify."): end proc: CheckA:=proc() global l,w,h,A1; local userA1; userA1:=Get(TFA::polynom(rational,[l,w,h]), corrections=true, update=true); if simplify(userA1-A1)=0 then Set(MRA="correct"); Set(reply="Great job go on to the volume constraint."); else Set(MRA="incorrect"); Set(reply="Think about it and try again."); end if; end proc: ShowA:=proc() Set(TFA=A1): end proc: HintV:=proc() Set(reply="The volume of a box is equal to the product of the area of the base and the height."): end proc: CheckV:=proc() global V1; local userV; userV:=Get(TFg::polynom(rational,[l,w,h]), corrections=true, update=true); if simplify(userV-V1)=0 then Set(MRg="correct"); Set(reply="Great job go on to the gradient of the surface area."); else Set(MRg="incorrect"); Set(reply="Think about it and try again."); end if; end proc: ShowV:=proc() Set(TFg=V1): end proc: HintgradA:=proc() Set(reply="The gradient of A is a vector containing the derivatives of A with respect to each input variable."): end proc: CheckgradA:=proc() global l,w,h,gradA; local usergradA; usergradA:=parse(Get(TFgradA),statement); if IsEqual(usergradA,gradA) then Set(MRgradA="correct"); Set(reply="Great job go on to the gradient of the volume."); else Set(MRgradA="incorrect"); Set(reply="Think about it and try again."); end if; end proc: ShowgradA:=proc() Set(TFgradA=gradA): end proc: HintgradV:=proc() Set(reply="The gradient of V is a vector containing the derivatives of V with respect to each input variable."): end proc: CheckgradV:=proc() global l,w,h,gradV; local usergradV; usergradV:=parse(Get(TFgradV),statement); if IsEqual(usergradV,gradV) then Set(MRgradV="correct"); Set(reply="Great job go on to the Lagrange equations."); else Set(MRgradV="incorrect"); Set(reply="Think about it and try again."); end if; end proc: ShowgradV:=proc() Set(TFgradV=gradV): end proc: HintLagrange:=proc() Set(reply="The nth element of the gradient of A is equal to lambda times the nth element of the gradient of g."): end proc: CheckLagrange:=proc() global l,w,h,LEs; local userL1,userL2,userL3; userL1:=parse(Get(TFLE_l),statement); userL2:=parse(Get(TFLE_w),statement); userL3:=parse(Get(TFLE_h),statement); if IsEqual([userL1,userL2,userL3],LEs) then Set(MRLE="correct"); Set(reply="Great job; now find the dimensions of the box."); else Set(MRLE="incorrect"); Set(reply="Think about it and try again."); end if; end proc: ShowLagrange:=proc() Set(TFLE_l=LEs[1]): Set(TFLE_w=LEs[2]): Set(TFLE_h=LEs[3]): end proc: Hintdims:=proc() Set(reply="Solve for lambda, then use that value to relate one variable to the other two."): end proc: Checkdims:=proc() global dimsarray; local userl,userw,userh; userl:=parse(Get(TFl)); userw:=parse(Get(TFw)); userh:=parse(Get(TFh)); if IsEqual([userl,userw,userh],dimsarray) then Set(MRlwh="correct"); Set(reply="Great job; now find the surface area of the box."); else Set(MRlwh="incorrect"); Set(reply="Think about it and try again."); end if; end proc: Showdims:=proc() Set(TFl=Lvalue): Set(TFw=Wvalue): Set(TFh=Hvalue): end proc: HintAmin:=proc() Set(reply="Plug your values for the dimensions of the box into the surface area equation."): end proc: CheckAmin:=proc() global A1value; local userA1value; userA1value:=parse(Get(TFA1value)); if userA1value=A1value then Set(MRA1value="correct"); Set(reply="Congratulations, you solved the problem."); else Set(MRA1value="incorrect"); Set(reply="Think about it and try again.");\ end if; end proc: ShowAmin:=proc() Set(TFA1value=A1value): end proc: MinSurfArea:=Maplet(onstartup=RunWindow(MAIN), Window[MAIN](title="Minimize the Surface Area of a Box with a Given Volume", [ [ halign=none, Button("New Problem",Evaluate(function="NewProblem"),background=magenta), HorizontalGlue(), Button("Quit",Shutdown(),background=pink) ], [ TextBox[TBProb]( width=50, height=2, sprintf(" Minimize the surface area of a rectangular box without a lid whose volume is %a.",V0)) ], [ halign=none, border=true, caption="Write a function for surface area:", "A(l,w,h) =", TextField[TFA](width=12, background=turquoise), HorizontalGlue(), Button("Hint",Evaluate(function="HintA"),background=Orange), Button("Check",Evaluate(function="CheckA"),background=green), TextField[MRA](width=6,editable=false), Button("Show",Evaluate(function="ShowA"),background=yellow) ], [ halign=none, border=true, caption="Write the constraint equation for the volume:", "V(l,w,h) =", TextField[TFg](width=10, background=turquoise), Label[LeqV0]("= V0"), HorizontalGlue(), Button("Hint",Evaluate(function="HintV"),background=Orange), Button("Check",Evaluate(function="CheckV"),background=green), TextField[MRg](width=6,editable=false), Button("Show",Evaluate(function="ShowV"),background=yellow) ], [ halign=none, border=true, caption="Find the gradient of A in the form [A_l,A_w,A_h]:", "grad A =", TextField[TFgradA](width=20, background=turquoise), HorizontalGlue(), Button("Hint",Evaluate(function="HintgradA"),background=Orange), Button("Check",Evaluate(function="CheckgradA"),background=green), TextField[MRgradA](width=6,editable=false), Button("Show",Evaluate(function="ShowgradA"),background=yellow) ], [ halign=none, border=true, caption="Find the gradient of V in the form [V_l,V_w,V_h]:", "grad V =", TextField[TFgradV](width=20, background=turquoise), HorizontalGlue(), Button("Hint",Evaluate(function="HintgradV"),background=Orange), Button("Check",Evaluate(function="CheckgradV"),background=green), TextField[MRgradV](width=6,editable=false), Button("Show",Evaluate(function="ShowgradV"),background=yellow) ], [ halign=none, border=true, caption="Write out the Lagrange equations, grad A = lambda * grad V:", [ TextField[TFLE_l](width=20, background=turquoise), TextField[TFLE_w](width=20, background=turquoise), TextField[TFLE_h](width=20, background=turquoise) ], HorizontalGlue(), Button("Hint",Evaluate(function="HintLagrange"),background=Orange), Button("Check",Evaluate(function="CheckLagrange"),background=green), TextField[MRLE](width=6,editable=false), Button("Show",Evaluate(function="ShowLagrange"),background=yellow) ], [ halign=none, border=true, caption="Use the Lagrange equations and the constraint to solve for the dimensions of the box.", "l =", TextField[TFl](width=5, background=turquoise), HorizontalGlue(), "w =", TextField[TFw](width=5, background=turquoise), HorizontalGlue(), "h =", TextField[TFh](width=5, background=turquoise), HorizontalGlue(), Button("Hint",Evaluate(function="Hintdims"),background=Orange), Button("Check",Evaluate(function="Checkdims"),background=green), TextField[MRlwh](width=6,editable=false), Button("Show",Evaluate(function="Showdims"),background=yellow) ], [ halign=none, border=true, caption="Compute theta surface area.", "A =", TextField[TFA1value](width=20, background=turquoise), HorizontalGlue(), Button("Hint",Evaluate(function="HintAmin"),background=Orange), Button("Check",Evaluate(function="CheckAmin"),background=green), TextField[MRA1value](width=6,editable=false), Button("Show",Evaluate(function="ShowAmin"),background=yellow) ], [ halign=center, TextField[reply](width=55,editable=false, background=white) ], [ halign=none, "Instructor: Philip Yasskin", " ", HorizontalGlue(), "Programmers: Mark Collins & Carlo De Guzman", " ", HorizontalGlue(), "© Copyright 2014 Yasskin" ] ])): Maplets[Display](MinSurfArea);