kill(all)$

maxima:reactor:appendix: equilibrium constant relations,version 1.0
peter.vlasschaert@gmail.com,10/08/2021

load packages ,option
-------------------------------

load(lrats)$
ratprint:false$

equilibrium constant: K,K[P],K[Υ],K[Co]
------------------------------------------------------

K:a*A +b*B ⇔ c*C+d*D,  equilibrium constant , equation
-----------------------------------------------------------------------------

p1:a*A +b*B = c*C+d*D;

pb1:[A,B];/*products before the reaction*/
pa1:[C,D];/*products after the  reaction */

p2:expand(p1/a);

p1a:sort(flatten([args(lhs(p1)),args(rhs(p1))]));

p1b:1/a*p1a;

coef : reaction 'p1'
-------------------------

→ before

p1cb:makelist((-1)*ratcoeff(p1b[i],pb1[i]),i,1,length(pb1));

p1cba:(-1)*p1cb;

→ after

p1ca:makelist(ratcoeff(p1b[i+length(pb1)],pa1[i]),i,1,length(pa1));

p1cc:Δ=sum(flatten([[p1cb],[p1ca]])[i],i,1,4);

p1ccc:reverse(p1cc);

activity :a[i], species

definition 1: f[i] =fugacity f0[i], ref : 1atm (gases)

p3a:a[i]=f[i]/f0[i];

definition 2:γ[i] =activity cof.,P[i]=partial pressure

p3b:a[i]=γ[i]*P[i];

i: takes values A,B,C,D, √ products

Definition ; equilibrium constant = K
-------------------------------------------------

p4:K = K[Υ]*K[P];

use :p2

mm(ia,va):=(a[ia])^va;

m1:mm(C,p1ca[1]);
m2:mm(D,p1ca[2]);
m3:mm(A,p1cba[1]);
m4:mm(B,p1cba[2]);

p4a:K=((m1*m2)/(m3*m4));

Definition :gas law : P*V=R*T*n
---------------------------------------------
partial pressure &  concentration=Co[i],i=A,B,C,D

p5a:P*V=R*T*n;

p5b:p5a/V;

p5c:[P=P[i],n=n[i]];

p5d:subst(p5c,p5b);

p5e:[n[i]/V=Co[i]];

p5f:lratsubst(p5e,p5d);

p5f1:rhs(p5f);

computation : K[Υ],K[P]
--------------------------------

mmm(aa,ia,va):=(aa[ia])^va;

→ K[P]

m1a:mmm(P,C,p1ca[1]);
m2a:mmm(P,D,p1ca[2]);
m3a:mmm(P,A,p1cba[1]);
m4a:mmm(P,B,p1cba[2]);

p6a:K[P]=((m1a*m2a)/(m3a*m4a));

→ K[Υ]

m1b:mmm(Υ,C,p1ca[1]);
m2b:mmm(Υ,D,p1ca[2]);
m3b:mmm(Υ,A,p1cba[1]);
m4b:mmm(Υ,B,p1cba[2]);

p6b:K[Υ]=((m1b*m2b)/(m3b*m4b));

→K=K[P]*K[Υ]

K=subst([p6a,p6b],K[P]*K[Υ]);

K[P] & p5f1 & p6a

mm1(i):=P[i]=''p5f1;

m1c:mm1(C);
m2c:mm1(D);
m3c:mm1(A);
m4c:mm1(B);

p6c:subst([m1c,m2c,m3c,m4c],p6a);

p6c1:lhs(p6c)=radcan(rhs(p6c));

p6c2:lratsubst([p1ccc],p6c1);

find : K[Co]
----------------

maa:R^Δ*T^Δ;

p6c3:K[Co]=ratcoeff(rhs(p6c2),maa);

ideal gas :relation

find : K[P]= ?,Δ=?
-------------------------
Co = concentration .

p7:K[P]=(K[Co]*maa);

p7a:lhs(p7)=radcan(rhs(p7));/*nothing*/

p7b:log(p7a);

p7c:ev(p7b,logexpand = super);

p7d:lhs(p7c)=logcontract(rhs(p7c));

p7e:logcontract(solve(p7d,Δ))[1];