# Maximize a Monomial on a Plane # Jane Frederick & Sarah Jacobson # Math 253 Sec 201 Fall 2014 # Instructor: Yasskin # restart; with(Maplets[Tools]): with(Maplets[Elements]): with(plots): StartEngine(): randomize(): rollsum:= 10*rand(1..20): NewProblem:=proc() global a1,b1,c1,f1,sum1,g1,constreq,f2,fy1,fz1,y1,z1,x1; local xcon,ycon,fy2,fz2,sol; a1:=RandomTools[Generate](integer(range=1..3)); b1:=RandomTools[Generate](integer(range=1..3)); c1:=RandomTools[Generate](integer(range=1..3)); f1:=x^a1*y^b1*z^c1; sum1:=rollsum(); g1:=x+y+z; constreq:=g1=sum1; xcon:=solve(constreq,x); ycon:=solve(constreq,y); f2:=eval(f1,x=xcon); fy1:=simplify(diff(f2,y)); fy2:=fy1; while eval(fy2,y=0)=0 do fy2:=expand(fy2/y); end do; while eval(fy2,z=0)=0 do fy2:=expand(fy2/z); end do; fy2:=expand(eval(fy2,y=ycon)); while eval(fy2,x=0)=0 do fy2:=expand(fy2/x); end do; fy2:=expand(eval(fy2,x=xcon)); fz1:=simplify(diff(f2,z)); fz2:=fz1; while eval(fz2,y=0)=0 do fz2:=expand(fz2/y); end do; while eval(fz2,z=0)=0 do fz2:=expand(fz2/z); end do; fz2:=expand(eval(fz2,y=ycon)); while eval(fz2,x=0)=0 do fz2:=expand(fz2/x); end do; fz2:=expand(eval(fz2,x=xcon)); sol:=solve([fy2=0,fz2=0],{y,z}); y1:=eval(y,sol); z1:=eval(z,sol); x1:=eval(solve(constreq,x),sol); Set(Question=sprintf("Find three numbers x, y, and z whose sum is %a such that %a is a maximum.",sum1,f1)); Set(Leqsum(caption)=sprintf("= %a",sum1)); Set(TFfxyz=""); Set(TFg=""); Set(MRfxyz=""); Set(MRg=""); Set(TFfyz=""); Set(MRfyz=""); Set(TFfy=""); Set(MRfy=""); Set(TFfz=""); Set(MRfz=""); Set(TFy=""); Set(MRy=""); Set(TFz=""); Set(MRz=""); Set(TFx=""); Set(MRx=""); Set(reply=""); end proc: Hintfxyz:=proc() Set(reply="What does the question ask to be a maximum?"); Set(MRfxyz="hint"); end proc: Checkfxyz:=proc() global f1; local userf1; userf1:=Get(TFfxyz::algebraic, corrections=true, update=true); if userf1=f1 then Set(MRfxyz="correct"); Set(reply="You're a wizard Harry!"); else Set(MRfxyz="incorrect"); Set(reply="Try again."); end if; end proc: Showfxyz:=proc() global f1; Set(TFfxyz=f1); Set(MRfxyz="shown"); end proc: Hintg:=proc() Set(reply="What function can be solved for?"); Set(MRg="hint"); end proc: Checkg:=proc() global g1; local userg1; userg1:=Get(TFg::algebraic, corrections=true, update=true); if userg1=g1 then Set(MRg="correct"); Set(reply="Dobby is a free elf! because you are correct."); else Set(MRg="incorrect"); Set(reply="Try again."); end if; end proc: Showg:=proc() global g1; Set(TFg=g1); Set(MRg="shown"); end proc: Hintfyz:=proc() Set(reply="Solve the constraint equation from the previous question for x and plug into f(x,y,z)."); Set(MRfyz="hint"); end proc: Checkfyz:=proc() global f2; local userfyz1; userfyz1:=Get(TFfyz::algebraic, corrections=true, update=true); if simplify(userfyz1-f2)=0 then Set(MRfyz="correct"); Set(reply="You truely are a genius."); else Set(MRfyz="incorrect"); Set(reply="Try again."); end if; end proc: Showfyz:=proc() global f2; Set(TFfyz=f2); Set(MRfyz="shown"); end proc: Hintfy:=proc() Set(reply="Find the partial derivative of f(y,z) with respect to y."); Set(MRfy="hint"); end proc: Checkfy:=proc() global fy1; local userfy1; userfy1:=Get(TFfy::algebraic, corrections=true, update=true); if simplify(userfy1-fy1)=0 then Set(MRfy="correct"); Set(reply="You are the bomb.com!"); else Set(MRfy="incorrect"); Set(reply="Try again."); end if; end proc: Showfy:=proc() global fy1; Set(TFfy=fy1); Set(MRfy="shown"); end proc: Hintfz:=proc() Set(reply="Find the partial derivative of f(y,z) with respect to z."); Set(MRfz="hint"); end proc: Checkfz:=proc() global fz1; local userfz1; userfz1:=Get(TFfz::algebraic, corrections=true, update=true); if simplify(userfz1-fz1)=0 then Set(MRfz="correct"); Set(reply="You're so smart, you could be in Ravenclaw."); else Set(MRfz="incorrect"); Set(reply="Try again."); end if; end proc: Showfz:=proc() global fz1; Set(TFfz=fz1); Set(MRfz="shown"); end proc: Hinty:=proc() Set(reply="Solve the previous equations for y."); Set(MRy="hint"); end proc: Checky:=proc() global y1; local usery1; usery1:=Get(TFy::algebraic, corrections=true, update=true); if usery1=y1 then Set(MRy="correct"); Set(reply="Great job!"); else Set(MRy="incorrect"); Set(reply="Try again."); end if; end proc: Showy:=proc() global y1; Set(TFy=y1); Set(MRy="shown"); end proc: Hintz:=proc() Set(reply="Solve the previous equations for z."); Set(MRz="hint"); end proc: Checkz:=proc() global z1; local userz1; userz1:=Get(TFz::algebraic, corrections=true, update=true); if userz1=z1 then Set(MRz="correct"); Set(reply="Great job!"); else Set(MRz="incorrect"); Set(reply="Try again."); end if; end proc: Showz:=proc() global z1; Set(TFz=z1); Set(MRz="shown"); end proc: Hintx:=proc() Set(reply="Enter y and z into the constraint equation to find x."); Set(MRx="hint"); end proc: Checkx:=proc() global x1; local userx1; userx1:=Get(TFx::algebraic, corrections=true, update=true); if userx1=x1 then Set(MRx="correct"); Set(reply="Great job!"); else Set(MRx="incorrect"); Set(reply="Try again."); end if; end proc: Showx:=proc() global x1; Set(TFx=x1); Set(MRx="shown"); end proc: MaximizeXYZ:=Maplet(onstartup=RunWindow(MAIN), Window[MAIN](title="Maximize a Monomial on a Plane", [ [ halign=none, Button("New Problem", Evaluate(function="NewProblem"),background=magenta), HorizontalGlue(), Button("Quit",Shutdown(),background=pink) ], [ border=true, TextBox[Question](width=70, height=2, "Find three numbers x, y, and z whose sum is 100 such that ( x ^ a ) * ( y ^ b ) * ( z ^ c ) is a maximum.") ], [ halign=none, border=true, caption="Step 1: What function are you maximizing?", "f(x,y,z) =", TextField[TFfxyz](width=20,background=turquoise), HorizontalGlue(), Button("Hint",Evaluate(function="Hintfxyz"),background=DarkOrange), Button("Check",Evaluate(function="Checkfxyz"),background=green), TextField[MRfxyz](width=6), Button("Show",Evaluate(function="Showfxyz"),background=yellow) ], [ halign=none, border=true, caption="Step 2: What is the constraint function?", "g(x,y,z) =", TextField[TFg](width=20,background=turquoise), Label[Leqsum]("= 100"), HorizontalGlue(), Button("Hint",Evaluate(function="Hintg"),background=DarkOrange), Button("Check",Evaluate(function="Checkg"),background=green), TextField[MRg](width=6), Button("Show",Evaluate(function="Showg"),background=yellow) ], [ halign=none, border=true, caption="Step 3: Solve the constraint for x and substitute into f:", "f(y,z) =", TextField[TFfyz](width=20,background=turquoise), HorizontalGlue(), Button("Hint",Evaluate(function="Hintfyz"),background=DarkOrange), Button("Check",Evaluate(function="Checkfyz"),background=green), TextField[MRfyz](width=6), Button("Show",Evaluate(function="Showfyz"),background=yellow) ], BoxColumn( halign=none, inset=0, border=true, caption="Step 4: Set the gradient of f equal to 0:", [ halign=none, "fy =", TextBox[TFfy](width=40,height=2,background=turquoise), "= 0", HorizontalGlue(), Button("Hint",Evaluate(function="Hintfy"),background=DarkOrange), Button("Check",Evaluate(function="Checkfy"),background=green), TextField[MRfy](width=6), Button("Show",Evaluate(function="Showfy"),background=yellow) ], [ halign=none, "fz =", TextBox[TFfz](width=40,height=2,background=turquoise), "= 0", HorizontalGlue(), Button("Hint",Evaluate(function="Hintfz"),background=DarkOrange), Button("Check",Evaluate(function="Checkfz"),background=green), TextField[MRfz](width=6), Button("Show",Evaluate(function="Showfz"),background=yellow) ] ), BoxColumn( halign=none, inset=0, border=true, caption="Step 5: Solve for y and z and plug back into the constraint to get x:", [ halign=none, "y =", TextField[TFy](width=15,background=turquoise), HorizontalGlue(), Button("Hint",Evaluate(function="Hinty"),background=DarkOrange), Button("Check",Evaluate(function="Checky"),background=green), TextField[MRy](width=6), Button("Show",Evaluate(function="Showy"),background=yellow) ], [ halign=none, "z =", TextField[TFz](width=15,background=turquoise), HorizontalGlue(), Button("Hint",Evaluate(function="Hintz"),background=DarkOrange), Button("Check",Evaluate(function="Checkz"),background=green), TextField[MRz](width=6), Button("Show",Evaluate(function="Showz"),background=yellow) ], [ halign=none, "x =", TextField[TFx](width=15,background=turquoise), HorizontalGlue(), Button("Hint",Evaluate(function="Hintx"),background=DarkOrange), Button("Check",Evaluate(function="Checkx"),background=green), TextField[MRx](width=6), Button("Show",Evaluate(function="Showx"),background=yellow) ] ), [ TextBox[reply](width=55,height=2) ], [ halign=none, "Instructor: Philip Yasskin", HorizontalGlue(), "Programmers: Jane Frederick & Sarah Jacobson", HorizontalGlue(), "© Copyright 2014 Yasskin" ] ] ) ): Maplets[Display](MaximizeXYZ);