kill(all)$

maxima : intro to residue curve ( = distillation curve,fixed α),version 1.0 ,part 5
peter.vlasschaert@gmail.com,01/10/2020

ref :conceptual design of distillation systems
       M.F.Doherty & M.F.Malone
       McGRAW-Hill International Editions.

load(draw)$load(lrats)$ ratprint:false$

distillation lines or curve (with fixed volatilities:=α)
=====================================

1e) step : essential for ternary plot (without code)
------------------------------------------------------------------

lp(a_,b_):=a_*t+b_*(1-t);

f:sqrt(3)/20 $/* scaling factor,*/

s1x:[(k/sqrt(3))*f,((20-k)/sqrt(3))*f]$
s1y:k*f$ /* y values are fixed values */
s1:[k/sqrt(3)*t+(20-k)/sqrt(3)*(1-t),k]$
p1:makelist(makelist
  ([ev(lp(s1x[1],s1x[2]),nouns),ev(s1y,nouns)],
   t,0,1,0.1),k,0,10),float$

s2x:[((k+10)/sqrt(3))*f,((2*k)/sqrt(3))*f]$
s2y:[(10-k)*f,0*f]$
p2:makelist(makelist
([ev(lp(s2x[1],s2x[2]),nouns),ev(lp(s2y[1],s2y[2]),nouns)],
t,0,1,0.1),k,0,10)$

s3x:[((k)/sqrt(3))*f,((2*k)/sqrt(3))*f]$
s3y:[k*f,0*f]$
p3:makelist(makelist
([ev(lp(s3x[1],s3x[2]),nouns),ev(lp(s3y[1],s3y[2]),nouns)],
t,0,1,0.1),k,0,10)$

wxdraw2d( 
    font = Arial,
    font_size = 20,
    line_width =1,
    color = blue,
    point_size = 0.01, 
    points_joined = true,     
    makelist(points(p1[i]),i,1,length(p1)),    
    makelist(points(p2[i]),i,1,length(p2)),    
    makelist(points(p3[i]),i,1,length(p3)),
    /* here the source code  */
    /* distillation: line or curve,fixed
       volatilities α */
    /* end source code */
    /* info on the plot */
    color = black,   
    title = "Ternary plot {A,B,C}",
    color = red,
    label(["A",1/2+0.025,sqrt(3)/2-0.01]),
    label(["B",0+0.025,0+0.025]),
    label(["C",1-0.025,0+0.025]),       
    xtics =false,  /* removes numbers */
    ytics =false,  /* removes numbers */ 
    /* remove the frame     */
    axis_top    = false, 
    axis_bottom = false,
    axis_left   = false,
    axis_right  = false, 
    /* end remove the frame */   
    proportional_axes = 'xy 
         )$
 $

rem : A,B,C, chemical components , fixed volatilities.

2e) step :ternary  system "distillation curve" , α  values fixed
---------------------------------------------------------------------------------

nc1:3;

q1a:kk=nc1;

q1c:'sum(x[i],i,1,nc1) =1;

q1ca:ev(solve(q1c,x[nc1]),nouns);

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

q1d:y[i]=(x[i]*α[i,kk])/(x[kk]+'sum(x[jj]*α[jj,kk],jj,1,nc1-1));

kk = highest boiling point, C = component 'ternary plot'

q1da:lratsubst([kk=nc1],q1d);

→ use :q1ca in q1da

q1da1:lratsubst(q1ca,q1da);

q1da2:ev(q1da1,nouns);

q1da2a:num(rhs(q1da2));
q1da2b:factorsum(denom(rhs(q1da2)));

q1da3:lhs(q1da2)=q1da2a/q1da2b;

appendix:αα= fixed ,binary system
-------------------------------------------------

part a :appendix
-----------------------

z1a:x[1]+x[2] = 1;
z1a1:solve(z1a,x[2])[1];
z1b:y[1]+y[2] = 1;
z1b1:solve(z1b,y[2])[1];

z1c:αα[i,j]=(y[i]/x[i])/(y[j]/x[j])$ /* i≠j */
z1d:lratsubst([i=1,j=2],z1c);

z1da:lratsubst([z1a1,z1b1],z1d);

z1da1:solve(z1da,y[1])[1];

z1da1a:factorsum(num(rhs(z1da1)));
z1da1b:factorsum(denom(rhs(z1da1)));

z1db:lhs(z1da1)=z1da1a/z1da1b;

part b: elimination α[1,2]
----------------------------------

z2:solve(z1db,αα[1,2])[1];

z2a:z2*x[1]/(x[1]-1);

z2a1:lhs(z2a)=ratsimp(rhs(z2a));

part c:distilation curve
-------------------------------

→  x[1,j]   j=0,1,2,... n'  j =0, initial composition ', liquid.
→  y[1,j]   j=0,1,2,....n '                                           , vapor.

z3a:[x[1]=x[1,j],y[1]=y[1,j]];

z3b:lratsubst(z3a,z2a1);

→ j =0

z3b1:lratsubst([j=0],z3b);

z3b1a:reverse(z3b1);

part d :def :total condenstion = vapor comming from liquid
--------------------------------------------------------------------------------

z4a:x[1,ll+1]=y[1,ll];/* definition */

→ ll =0 ,first step

z4a1:subst([ll=0],z4a);
z4a2:reverse(z4a1);

z4a3:lratsubst([z4a2],z3b1);
z4a3a:reverse(z4a3);

→ ll=1 ,second step

z4b1:subst([ll=1],z4a);
z4b2:reverse(z4b1);

→ j=1

z5b1:lratsubst([j=1],z3b);
z5b2:reverse(z5b1);

→ use :z4a3a &z5b2

z5b3:lhs(z5b2)=ratcoef(rhs(z5b2),lhs(z4a3a))*rhs(z4a3a);

→use :z4b2

z5b4:lratsubst([z4b2],z5b3);

part e : j=n 

z6a:x[1,n]/(x[1,n]-1)=(x[1,0]*αα[1,2]^n)/(x[1,0]-1);

z6b:solve(z6a,x[1,n])[1];

z6c1:factorsum(num(rhs(z6b)));
z6c2:factorsum(denom(rhs(z6b)));

z6c:lhs(z6b) = z6c1/z6c2;

general form  (binary form)
=====================
y[1]=(x[1]*αα[1,2])/(x[1]*(αα[1,2]-1)+1)

z6c1:z6c;

z6c2:y[1]=(x[1]*αα[1,2])/(x[1]*(αα[1,2]-1)+1);

analoog:(ternary form)
==================

z7a:y[i]=(x[i]*α[i,3])/(x[2]*(α[2,3]-1)+x[1]*(α[1,3]-1)+1);

z7a1:lratsubst([i=1],z7a);
z7a2:lratsubst([i=2],z7a);

→ y[1]=x[1,n] ,y[2]=x[2,n] , α[i,j]→(α[i,j])^n ,j=3,see : binary form

z8b1:[y[1]=x[1,n],y[2]=x[2,n],α[1,3]=(α[1,3])^n,
     α[2,3]=(α[2,3])^n];

z8b2:lratsubst(z8b1,z7a1);
z8b3:lratsubst(z8b1,z7a2);

example : distillation curve
=====================
α1,α2,α3, mean relative 

→  input : 'data from: components'

α1:4.032;   /* A component,relative mean volatilities (respect :C) */
α2:1.339;   /* B component,relative mean volatilities (respect :C) */
x10:0.05;/* A component,initial concentration (=mole fractio),j=0 */
x20:0.36;/* B component,initial concentration (=mole fractio),j=0 */

→  equation  'distillation curve' : triangle triple (a=xx1(n),b=xx2(n),c=xx3(n))

xx1(n):=(x10*α1^n)/(x20*(α2^n-1)+x10*(α1^n-1)+1);
xx2(n):=(x20*α2^n)/(x20*(α2^n-1)+x10*(α1^n-1)+1);
xx3(n):=1-xx1(n)-xx2(n);

→  output 

fpprintprec : 4$

a) computation :triangle triple (a,b,c)
---------------------------------------------------

test : n=2 
------------- 

[xx1(2),xx2(2),xx3(2)];

n = .......-3,-2,-1,0,1,2,3,......................., n =integer
------------------------------------------------------------------

qq:[]$
nn:15$
for i:-nn thru nn do(
qq:endcons([xx1(i),xx2(i),xx3(i)],qq)   
)$

qq;

qq[1][1];

b) conversion : (a,b,c)  => (x_t,y_t), ' cartesian coordinates ,graph'
------------------------------------------------------------------------------------------

ref :maxima : intro to residue curve ( = ternary plot,load draw),version 1.0b ,part 4a
      peter.vlasschaert@gmail.com,01/10/2020

x_t(aa_,bb_,cc_) :=-(2*bb_+aa_-2)/2$
y_t(aa_,bb_,cc_) := sqrt(3)/2*aa_  $

qqq:[]$

for i:1 thru length(qq) do(
qqq:endcons([x_t(qq[i][1],qq[i][2],qq[i][3]),y_t(qq[i][1],qq[i][2],qq[i][3])],qqq)           
)$

float(qqq);

c) plot data ,ternary plot
--------------------------------

wxdraw2d( 
    font = Arial,
    font_size = 20,
    line_width =1,
    color = blue,
    point_size = 0.01, 
    points_joined = true,     
    makelist(points(p1[i]),i,1,length(p1)),    
    makelist(points(p2[i]),i,1,length(p2)),    
    makelist(points(p3[i]),i,1,length(p3)),
    /* here the source code  */
    color = red,   
    points(qqq),  
    label(["distillation curve",1/2,1/2]),
    /* end source code */
    /* info on the plot */
    color = black,   
    title = "Ternary plot {A,B,C}",
    color = red,
    label(["A",1/2+0.025,sqrt(3)/2-0.01]),
    label(["B",0+0.025,0+0.025]),
    label(["C",1-0.025,0+0.025]),       
    xtics =false,  /* removes numbers */
    ytics =false,  /* removes numbers */ 
    /* remove the frame     */
    axis_top    = false, 
    axis_bottom = false,
    axis_left   = false,
    axis_right  = false, 
    /* end remove the frame */   
    proportional_axes = 'xy 
         ),wxplot_size=[600,600]$