kill(all)$

maxima :partial molar properties,version 1.0
peter.vlasschaert@gmail.com,12/09/2020

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

load(lrats)$ ratprint:false$

nc:4;   /*(n)umber of (c)omponents = nc */

def : MA = M(T,P,x[1],x[2],....,x[k],..  .x[nc])    (1)
def : MB = M(T,P,x[1],x[2],....,x[k],.....x[nc])    (2)  ,constraint, T =cte,P=cte
========================================================

r1:MA = diff( M (T,P,x[1],x[2],x[3],x[4]));

r2a:[del(P)=0,del(T) =0];
r2b:MB = lratsubst(r2a,rhs(r1));

r2c:listofvars(rhs(r2b));

r2da:makelist(r2c[i],i,1,2);

r2db:makelist(r2c[i],i,length(r2da)+1,length(r2c));

r3e:lhs(r2b)='sum('diff(M(T,P,x[1],x[2],x[3],x[4]),x[i])*del(x[i]),i,1,nc);

r3d:ev(r3e,nouns);

? Def : MA

r4:lhs(r1)= sum(part(rhs(r1),i),i,1,length(r2da))+rhs(r3e);

r5:'diff( M (T,P,x[1],x[2],x[3],x[4]))=rhs(r4);

b) mole fraction   x[i], i=1,2,..nc
=======================
example : nc = 4

r6a:n='sum(n[i],i,1,nc);

r6b:x[i]=n[i]/rhs(r6a);

r6b1:lratsubst([reverse(r6a)],r6b);

property : molefraction
-------------------------------

r6c1:sum(r6b,i,1,nc);

r6c2a:ev(r6c1,nouns);

r6c2b:ratsimp(r6c2a);

 c) def :: nM (=n*M) = m(T,P,x[1,x[2],...,x[nc])
=================================
n = factor 
intensive  properties (=solution)
extensive properties (M =H,V,U,C_v,C_p,S,A,G)
-------------------------------------------------------------------
T = temperature
P = pressure
S = Entropy
-------------------------------------------------------------------

H = Enthalpy  = U +P*V = (U + R*T )    , P*V = R*T (=ideal gas) (3,3')
G = Gibbs      = H - T*S  ( free energy)                                           (4)               
A = Helmhotz = U -T*S  ( free energy)                                           (5)

assume(R>0);

r7: H = U+R*T;/*definition :ideal gas,(3'),(3) */

r7a:'diff(lhs(r7),T)='diff(part(rhs(r7),1),T)+diff(part(rhs(r7),2),T);

r7b:C_p =C_v+R; /*index is constant , C = heat capacity*/

r7c:solve(r7b,R)[1];/*gas constant ( =ideal gas)*/

def : heat capacity ( by constant pressure),(6)
----------------------------------------------------------

r7da:lhs(r7b) = lhs(r7a);

def : heat capacity ( by constant volume),(7)
----------------------------------------------------------

r7db:lratsubst([R=0],rhs(r7b)=rhs(r7a));

def :(ideal gas =R),(8)
------------------------------
see :above.

rdc:r7c;

functional dependence :nM = n*M
==========================
use :lhs,r5 after r5

r8a:args(lhs(r5));/*M(....)= M */

r8b1:[r8a[1]=nM];
r8b2:lratsubst(r8b1,r5)$

a) part
----------

r8b2a:lratsubst([x[i]=n[i]],r8b2);

r8c1:part(rhs(r8b2),1) = n*'diff(M,T)*del(T);
r8c1a:part(rhs(r8b2),2) = n*'diff(M,P)*del(P);

r8c2:r8c1/del(T);
r8c2a:r8c1a/del(P);

r8c2b:args(part(rhs(r8b2a),3));

r8c2c:part(r8c2b[1],1)='diff(n*M,n[i]);

b) part
---------
use : r8c2,r8c2a,r8c2c into r8b2a

r9:[r8c2,r8c2a,r8c2c];

r9a:lratsubst(r9,r8b2a);

P,T ,constant 
--------------------

r9a1:lratsubst([del(T)=0,del(P)=0],r9a);

r9a2:args(rhs(r9a1));

c) New definition: Mbar[i],i=1,2,...nc-1,nc (r10)  
----------------------------------------------------------------
use : r8c2c ,rhs

r10:Mbar[i] = rhs(r8c2c); /*P,T ,constant */

r10a:reverse(r10);

Mbar[i] = f(T,P,composition ),homogeneous fluid @ equilibrium (PVT,  system)

d) use New definition.
------------------------------
into :r9a  & r10a

r11:lratsubst([r10a],r9a);

Euler's theorem ( = homogeneousnfunction  :properties , M,nM)
================================================
see website :
new: 08/09/2020:maxima :appendix extensive properties thermodynamics,version 1.0
---------------------------------------------------------------------------------------------------------------------
(  →  F(α*z[i]) = α^m*F(z[i]) → m*F =sum(z[i]*diff(F,z[i])), F = M  )

r12:n*M = 'sum(n[i]*Mbar[i],i,1,nc); 

r12a:r12/n;

use definition : molefraction

r12b:lratsubst([reverse(r6b1)],r12a);

pure component  k,  ( x[k]=1)
===============

r13:M[k] =MBar[k];

prove : :x[k]=1, nc =4 ,divide by 4
----------------------------------------------

a)  analyse :r12b
-----------------------

r13a:args(rhs(r12b));

b) pure component=k
------------------------------

r13b:lratsubst([i=k],r13a[1]);

c) replace into :r12b
-----------------------------

r13b1:[r13a[1]=r13b];

d)  use of  r13 & x[k] = 1
----------------------------------

r13b2:append(r13b1,[x[k]=1]);

r13b2a:lhs(r13)=(lratsubst(r13b2,rhs(r12b)))/nc;

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

rem : F(α*z[i]) = α^m*F(z[i]) → m*F =sum(z[i]*diff(F,z[i])), F = M
          