# Equilibrium Concentrations in Chemical Reactions # Aaron Milhorn # Math 151 Honors Section 201 # Fall 2013 # Instructor: Philip Yasskin # # Serious # # # Not serious # It is great. # I added a few more %f formating parameters. # I added =k0 after the equil constant expression to turn it into the equation which needs to be solved. # The only things I would add is a calculator to find x, so they don't need to pull out a hand calculator # and a plot of the equation so they can see the solution. Or instead of the line where they enter x, have them clear the denominator on the equation with the Check or show button automatically solving it and displaying the x value on another line. If you want to continue working on this after the end of the semester, I would be happy to work with you. # # Is it correct to allow initial concentrations to be 1.00? # Do the initial concentrations need to total to less than 1? # restart: with(Maplets[Tools]): with(Maplets[Elements]): with(plots): with(plottools): StartEngine(); randomize(): randCons:=evalf(rand(0..100)/100.,2): randabc:=rand(1..5): randk:=evalf(rand(0..99)/10000.,2): ask:=proc() global eqex, exx, x0, CAf, CBf, CCf; local CA0,CB0, a0, b0, c0, k0; CA0,CB0:=randCons(),randCons(); a0,b0,c0:=randabc(),randabc(),randabc(); k0:=randk(); eqex:= cC^c0/((cA^a0)*(cB^b0)); exx := (c0*x)^c0/((CA0-a0*x)^a0)/((CB0-b0*x)^b0); x0 := min(evalf(fsolve((c0*x)^c0=k0*((CA0-a0*x)^a0)*((CB0-b0*x)^b0),x=0..1),3)); CAf := evalf((CA0-x0*a0),3); CBf := evalf((CB0-x0*b0),3); CCf := evalf((x0*c0),3); Set(MMLeq(value)=(a0*A+b0*B &*`Ì`&* c0*C)); Set(TFProb=sprintf(" Consider a reaction mixture whose initial concentrations are\n cA_i = %4.4f M and cB_i = %4.4f M\nand whose the equilibrium constant is K = %4.4f.\nFind the final equilibrium concentrations of A, B and C.", CA0, CB0, k0)); Set(LK(caption)=sprintf("= %4.4f", k0)); Set(TFK1=""); Set(replyK1="",replyK1(background)=white); Set(TFK2=""); Set(replyK2="",replyK2(background)=white); Set(TFx=""); Set(replyx="",replyx(background)=white); Set(TFCA=""); Set(TFCB=""); Set(TFCC=""); Set(replyCons="",replyCons(background)=white); Set(reply=""); end proc: hintK1:=proc() Set(reply="The equilibrium expression is a ratio of products to reactants") end proc: checkK1:=proc() global eqex,cA, cB, cC, a0, b0, c0, exx, CAf, CBf, CCf; local userK1; userK1:=Get(TFK1::anything, corrections=true, update=true); if userK1=eqex then Set(replyK1="Correct", replyK1(background)=green, replyK1(foreground)=black); Set(reply="Good work!") else Set(replyK1="Incorrect", replyK1(background)=red, replyK1(foreground)=white); Set(reply="Try again.") end if; end proc: showK1:=proc() global eqex,cA, cB, cC, a0, b0, c0, exx, CAf, CBf, CCf; Set(TFK1=eqex); Set(replyK1="Shown", replyK1(background)=yellow, replyK1(foreground)=black); Set(reply="") end proc: hintK2:=proc() Set(reply="Consider the stoichiometric relationships between the three components.") end proc: checkK2:=proc() global eqex,cA, cB, cC, a0, b0, c0, exx, CAf, CBf, CCf; local userK2; userK2:=Get(TFK2::anything, corrections=true, update=true); if userK2=exx then Set(replyK2="Correct", replyK2(background)=green,replyK2(foreground)=black); Set(reply="Good work!") else Set(replyK2="Incorrect", replyK2(background)=red, replyK2(foreground)=white); Set(reply="Try again.") end if; end proc: showK2:=proc() global eqex,cA, cB, cC, a0, b0, c0, exx, CAf, CBf, CCf; Set(TFK2=exx); Set(replyK2="Shown", replyK2(background)=yellow,replyK2(foreground)=black); Set(reply="") end proc: hintx:=proc() Set(reply="Solve for x using the equilibrium constant equation.") end proc: checkx:=proc() global eqex,cA, cB, cC, a0, b0, c0, exx, CAf, CBf, CCf; local userx; userx:=Get(TFx::anything, corrections=true, update=true): if evalf(abs(userx-x0))<=.01*x0 then Set(replyx="Correct!",replyx(background)=green, replyx(foreground)=black); Set(reply="Great work!") else Set(replyx="Incorrect", replyx(background)=red, replyx(foreground)=white); Set(reply="Try again.") end if; end proc: showx:=proc() global eqex,cA, cB, cC, a0, b0, c0, exx, CAf, CBf, CCf; Set(TFx=sprintf("%5.5g",x0)): Set(replyx="Shown", replyx(background)=yellow, replyx(foreground)=black); Set(reply="") end proc: hintCons:=proc() Set(reply="Use the x found in the previous step with the initial concentrations.") end proc: checkCons:=proc() global eqex,cA, cB, cC, a0, b0, c0, exx, CAf, CBf, CCf; local userCA, userCB, userCC; userCA:=Get(TFCA::anything, corrections=true, update=true): userCB:=Get(TFCB::anything, corrections=true, update=true): userCC:=Get(TFCC::anything, corrections=true, update=true): if evalf(abs(userCA-CAf)<.01*CAf) and evalf(abs(userCB-CBf)<.01*CBf) and evalf(abs(userCC-CCf)<.01*CCf) then Set(replyCons="Correct!",replyCons(background)=green, replyCons(foreground)=black ); Set(reply="Good work!") else Set(replyCons="Incorrect.",replyCons(background)=red, replyCons(foreground)=white ); Set(reply="Try again.") end if; end proc: showCons:=proc() global eqex,cA, cB, cC, a0, b0, c0, exx, CAf, CBf, CCf; Set(TFCA=sprintf("%5.5f",CAf)): Set(TFCB=sprintf("%5.5f",CBf)): Set(TFCC=sprintf("%6.6f",CCf)): Set(replyCons="Shown", replyCons(background)=yellow, replyCons(foreground)=black); Set(reply="") end proc: Equilibrium:=Maplet(onstartup=RunWindow(MAIN), Window[MAIN](title="Equilibrium Concentrations in Chemical Reactions", [ valign=none, inset=0, spacing=0, [ halign=none, Button("New Problem", Evaluate(function="ask"), background=magenta), HorizontalGlue(), BoxRow( valign=none, inset=0, spacing=0, border=true, caption="Consider a chemical reaction of the form:", " ", MathMLViewer[MMLeq](value=(a*A+b*B &*`Ì`&* c*C), width=150, height=40), " " ), HorizontalGlue(), Button("Quit",Shutdown(), background=pink) ], [ halign=none, border=true, caption="Problem Statement:", TextBox[TFProb]( width=75, height=4, sprintf(" Consider a reaction mixture whose initial concentrations are\n cA_i = %a M and cB_i = %a M\nand whose the equilibrium constant is K = %a.\nFind the final equilibrium concentrations of A, B and C.", CAi, CBi, k)) ], [ halign=none, border=true, caption="Step 1: Write the equilibrium constant expression in terms of the general concentrations, cA, cB and cC:", "K=", TextBox[TFK1](width=30, height=1, background=turquoise), HorizontalGlue(), Button("Hint", Evaluate(function="hintK1"), background="Orange"), Button("Check", Evaluate(function="checkK1"), background=green), TextField[replyK1](width=6, editable=false, background=white), Button("Show", Evaluate(function="showK1"), background="Yellow") ], [ halign=none, border=true, caption="Step 2: Rewrite the equilibrium constant expression using the extent of reaction constant, x, and initial concentrations:", "K=", TextBox[TFK2](width=30, height=1, background=turquoise), Label[LK]("= k"), HorizontalGlue(), Button("Hint", Evaluate(function="hintK2"), background="Orange"), Button("Check", Evaluate(function="checkK2"), background=green), TextField[replyK2](width=6, editable=false, background=white), Button("Show", Evaluate(function="showK2"), background="Yellow") ], [ halign=none, border=true, caption="Step 3: Determine the magnitude of the extent of reaction:", "x = ", TextBox[TFx](width=10,background=turquoise), HorizontalGlue(), Button("Hint", Evaluate(function="hintx"), background="Orange"), Button("Check", Evaluate(function="checkx"), background=green), TextField[replyx](width=6, editable=false, background=white), Button("Show", Evaluate(function="showx"), background="Yellow") ], [ halign=none, border=true, caption="Step 4: Find the equilibrium concentrations:", "cA_f =", TextBox[TFCA](width=10, background=turquoise), "cB_f =", TextBox[TFCB](width=10, background=turquoise), "cC_f =", TextBox[TFCC](width=10, background=turquoise), HorizontalGlue(), Button("Hint", Evaluate(function="hintCons"), background="Orange"), Button("Check", Evaluate(function="checkCons"), background=green), TextField[replyCons](width=6, editable=false, background=white), Button("Show", Evaluate(function="showCons"), background=yellow) ], TextBox[reply](width=60, height=2), [ halign=none, inset=0, spacing=0, "Instructor: Philip Yasskin", HorizontalGlue(), "Programmers: Aaron Milhorn", HorizontalGlue(), "Copyright: Yasskin 2013" ] ] ) ): Maplets[Display](Equilibrium);