kill(all)$

peter.vlasschaert@gmail.com,16/06/2017
thermodynamics : 'Equation of State' 
1e) virial gas equation state

The virial gas equation of state ( thrid order)
--------------------------------
ideal     gases: P*V=R*T*n ,' n = number mole '
non-ideal gases: Z = (P*V)/(R*T),Z ' = compressibility factor '
                 z = Z1 = Z2

p1:(a+b+c+d)^3;

p2:expand(p1);

coeff(p2,d);

p11:(P*V)/(R*T);

Z(V)=Z1=1+B/V+C/V^2+D/V^3
Z(P)=Z2=1+B1*P+C1*P^2+D1*P^3

p3:Z1=1+B/V+C/V^2+D/V^3;
p4:Z2=1+B1*P+C1*P^2+D1*P^3;

? P=P(T,Bi,Ci,Di,B,C,D)  i=1,2,3....

p5:ratsubst(p11, Z1, p3);
p6:lhs(p5)*R*T/V=rhs(p5)*R*T/V;

p(i):=coeff(radcan(num(rhs(p6))),V^i)*V^i/denom(rhs(p6));
p00:num(rhs(p6))$
p000:ev(p00,V=0)/denom(rhs(p6))$
pt:p000+p(1)+p(2)+p(3);

 Z2=Z(T,V,Bi,Ci,Di,B,C,D)  i=1,2,3...

p7:subst(pt, P, p4);

p8:expand(p7);

new Z2 with old Z1     : coefficient comparing

part 1 : new Z2

for i:1 thru 12 do
pp(i):=subst(x^i, 1/V^i, p8)$
ppp(i):=coeff(rhs(pp(i)),x^(i))$

pp(2);
ppp(2);

part 2 : old Z1

for i:1 thru 4 do
qq(i):=subst(x^i, 1/V^i, p3)$
qqq(i):=coeff(rhs(qq(i)),x^(i))$

qq(2);
qqq(2);

coefficient : old Z2 ( 'p4')

q1:part(solve(ppp(1)=qqq(1),B1),1);
q2:part(solve(ppp(2)=qqq(2),C1),1);
q3:part(solve(ppp(3)=qqq(3),D1),1);

qq1:q1;
qq2:ev(q2,q1);
qq3:ev(q3,q1,qq2);

find : Z2=Z(P,T,C,B,D)

pq:ev(p4,qq1,qq2,qq3);

general : v=volume
          p=pressure
          Z=compressibility factor
          n= integer
---------------------------
 Z=1+sum(a(i)*1/v^i,i=1..n)
 z=1+sum(a1(i)*p^i ,i=1..n)
---------------------------