kill(all)$

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

ref:website
maxima : intro to residue curve ( = simple batch process),version 1.0,part 1

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

load(lrats)$ ratprint:false$

x[i],y[i] :mole fraction (liquid phase,vapor phase)

principal : simple distillation
=====================
input = output + accumulation

p1a : input = output + accumulation;
p1b : input = 0;
p1c : lratsubst([p1b],p1a);
p1d : solve(p1c,accumulation)[1];

(n)umber of (c)omponents 
====================

p1e:nc=n;

accumulation : change with time

1e)  Mass Balance
===============
use :p1d

p2a:accumulation = 'diff(L,t);
p2b:output       = V;
p2c:lratsubst([p2a,p2b],p1d);

L:depends on time

depends(L,t);

→ vapor escape rate (= time depent)

p2d:ev(p2c,diff);

2e) Component Balance
===================
i = 1,2,.., (n-1),independent component balances

depends(x_i,t);

p3a:'diff(L*x_i,t) = -V*y_i;

a) evaluation 
-------------------

' to protect evaluation : differentation

p3b:ev(p3a,nouns);

b) insert mass balance (p2d)
----------------------------------------

p3c:subst([p2d],p3b);

p3c1:part(lhs(p3c),1);
p3c2:part(lhs(p3c),2);

p3d:p3c-(p3c2);

p3e:factorsum(p3d/L);

Maxima : always put (-) before sum when allowed.(rhs)

→Q(t) follows then that V(t),L(t) function of time.
→ residue curve : exact time isn't inportant ( = warped time =z)
      dz = V/L*dt ( = How to do this in maxima)

→ time = t  to warped time = z ( = dimensionless ,domain =[0,∞ [)

p3f1:del(z) = V/L*del(t)$
p3f2a: dz = V/L*dt;
p3f2b:solve(p3f2a,dt)[1];
p3f2c:ratcoef(rhs(p3f2b),dz);
p3f3:lratsubst([t=z],lhs(p3e))=
     p3f2c*rhs(p3e);

c) final equation,p3f3
------------------------------

p4:p3f3;

rem :z=0→t=0

c1)  x_i → x[i],y_i →y[i]
--------------------------------

p4a:sort(listofvars(p4));

p4b:[x[i],y[i],z];

p4c:map("=",p4a,p4b);

c2)  n :components , i=1,2, ....,n-1
----------------------------------------------

p4da:p4d[j]:=subst([i=j],lratsubst(p4c,p4));

p4db:p4d[5];

c3) makelist from c2)
------------------------------

n:3;/*number of components */

p4dc:makelist(p4d[j],j,1,n-1);  /*why n-1 ,'see above'*/

rem : use :p3f2a , z depends on time
=============================

depends(z,t);

p5:p3f2a;
p5a:lratsubst([(-1)*reverse(p2c)],p5);
p5b:p5a/dt;
p5c:[dz/dt = diff(z,t)];
p5d:lratsubst(p5c,p5b);
p5e:integrate(p5d,t);

p5f:z(t)=(subst([L=L0],log(L))-log(L));

p5f1:logcontract(p5f);

rem : math :ln → maxima :log

rem :z=0→t=0
===========

'limit(z(t),t,0) = limit(rhs(p5f1),L,L0);

see : y[i] = equilibrium relation part,1
-----------------------------------------------------
→ binary distillation ( y[i] = α*x[i]/(1+(α-1)*x[i]))

p6:p4d[i];

p6a: y[i] = α*x[i]/(1+(α-1)*x[i]);

p6b:lratsubst([p6a],p6);

p6b1:p6b,expand;

differential equations to solve
=======================
i=1,2,....n-1

p6c:p6b;