kill(all)$

maxima : intro to residue curve ( = simple batch process),version 1.0,part 1
peter.vlasschaert@gmail.com,05/09/2020.

load packages,option
=================

load(lrats)$ ratprint:false$

multicomponent mixture.
===================

nc:4$ /* numberof components  */

nr:4$ /*number of reference component,general nr = nc */

partial pressure : p[i] , i=1,2,..,nc
=========================
P = total pressure 

q1:P=sum(p[i],i,1,nc);

mole fraction
==========

x [i]: liquid,y[i]:vapour (=vapor), with  nc = nc1 (equality relation),i:1,2,..nc

q2a:sum(x[i],i,1,nc) =1; 
q2b:sum(y[i],i,1,nc) =1;

equilibrium relation K[i], i=12,...nc
=================================
K[i]: equilibrium relation for  i th component.

q3:y[i] = K[i]*x[i];

q3a:solve(q3,K[i])[1];

α[i,j] :relative volatility  (i with respect j)
=============================
1e)  definition : j =component  with the  highest bp  ( bp =(b)oiling (p)oint).
                          →  j = nr, 'see above'

q4:α[i,j]=lhs(q3a)/subst([i=j],lhs(q3a));

?  We need equation : p[i]
====================
pvap[i]: Antoine equation  (pvap : vapor pressure),component 'i',see
your book for units

q5a:p[i] = y[i]*P;
q5b:p[i] = x[i]*γ[i]*pvap[i];/*Raoult's law ,correction nonideal*/

rem : pvap[A,B,C ,T] ,T =temperature.( = K,°C or other ones)
-----------------------------------------------------------------------------------
          γ[i],activity coefficient  i th component 
rem : All components ( i :1,2,..nc)  = Mixture
rem :γ[i], use when nonideal ( = ideal (=γ[i]=1))

a) combination :{q5a,q5b}.
-------------------------------------

q5c:rhs(q5a) = rhs(q5b);

b) sum both sides 
---------------------------

q5d:factorsum(sum(q5c,i,1,nc));

→ use 'q2b'

q5d1:lratsubst([q2b],q5d);

c) combination a) & b)
-------------------------------

q5e:q5c/P;

q5e1:subst([q5d1],q5e);

d)  K[i]= f(pvap[i],P,γ[i])
---------------------------------

q5f:q5e/x[i];

q5f1:lhs(q3a) = rhs(q5f);

q5f2:lratsubst([i=j],q5f1);

e) second definition :α[i;j]
------------------------------------

q5g:lhs(q4)=rhs(q5f1)/rhs(q5f2);
q5g1:reverse(q5g);
            

f)  use j : nr
---------------

q5ha:subst([j=nr],q5g);

q5ha1:reverse(q5ha);

q5ha2:denom(lhs(q5ha1))*q5ha1;

makelist : q5ha2( i:1,2,..,nc)

q5ha3:makelist(lratsubst([i=j],q5ha2*x[i]),j,1,nc);

q5ha4:flatten([[q5ha2*x[i]],q5ha3]);

final result :y[i] , i=1,2,.., nc-1
------------------------------------
use :q5e1

q5i1:lratsubst(q5ha4,q5e1);

because :equation:y[1],y[2],.....y[nc-1]
---------------------------------------------------
y[nc]= 1-sum(y[i,i,1nc)

general equation: last ( = nr),see

q6a:y[i]=(x[i]*α[i,j])/(x[j]+sum(x[i]*α[i,j],i,1,nc1-1));

example : nc=4
=============

q6b:lratsubst([nc1=nc],q6a);

q6c:ev(lratsubst([j=4],q6b),nouns);

check : q6c & q5i1
===============

is(rhs(q5i1)=rhs(q6c));

-------------------------------------------------------------------------------------------------------------------------------------------------------------

→ part 2:use 'q6a', simple batch process

    more  general equation  (with use :ref, ' component with  highest bp ').
=======================================================

ref:4; /* ref component ,before j=4 */

s1:sum(if ref = i and ref ≠ 1  then α[j,ref]*x[j]:0 else 
    if ref = 1  then
     (((α[j,ref]*x[j])/sum(α[i,ref]*x[i],i,1,nc)))/nc
    else
    (((α[j,ref]*x[j])/sum(α[i,ref]*x[i],i,1,nc)))/(ref-1)
    /* ref =1 ,becomes infinite result,see:selection before */
    ,i,1,nc);
y[j]= lratsubst([α[ref,ref]=1],s1);

s3:block(sum(if ref = i and ref ≠ 1  then α[j,ref]*x[j]:0 else 
    if ref = 1  then
     (((α[j,ref]*x[j])/sum(α[i,ref]*x[i],i,1,nc)))/nc
    else
    (((α[j,ref]*x[j])/sum(α[i,ref]*x[i],i,1,nc)))/(ref-1)
    /* ref =1 ,becomes infinite result,selection before */
    ,i,1,nc),lratsubst([α[ref,ref]=1],%));

s4:lratsubst([j=i],s3) ; /* change of dummy index */

check : against ( q6c,s4)

is(rhs(q6c)=rhs(s4));

example : j =1
===========

s4:lratsubst([j=1,α[ref,ref]=1],s3);
s5:solve(s4,x[1])[1];

----------------------------------------------------------------------------------------------------------------------------------------------------------------