kill(all)$

Electrochemistry (part 1a : Thermodynamics  dG 'Gibbs free energy')
peter.vlasschaert@gmail.com, 19/02/2019

rem : no charged particles.  ( correction for dG =del(G),see below, part 1b).
rem : no chemical reactions ( correction for dG =del(G),see below, part 1b).

load ' packages'
=============
load(lrats)  : used for simplification.

load(lrats)$

p1:f1= a*f2;

differentation
===========

1e)  d(f*g) = df*g+f*dg   'product rule differentation'
------------------------------------------------------------------------
a = constant  ?   del(a) = 0  in 'p1'

p2:diff(p1);

2e ) How to learn Maxima : a = constant   ( 'p1')
-------------------------------------------------------

p3: declare(a,constant)$
p4:diff(p1);

3e) how to get lost property (= constant ) for 'a' 
-----------------------------------------------------------------

kill(a);

p5:diff(p1);

Definition ;  Gibbs free energy
========================
G = H - T*S    ' thermodynamic function'
H : enthalpy or heat content
T : absolute temperature
S : entropy

p6:  G= H -T*S;

differential form : Gibbs free energy , 'see above differentation'
============================
rem : only work 'mechanical work ' = P*V  = energy
P : pressure
V : volume
-----------------------------------------------------------------------------------------
rem : G = G(T,P)  ?
rem : no charged particles in the system .
-----------------------------------------------------------------------------------------

p7: diff(p6);

Definition ;  Enthalpy
========================
H = U +P*V    ' thermodynamic function'
U : internal energy of system

p8: H = U+P*V;

differential form : Enthalpy , 'see above differentation'
=====================

p9:diff(p8);

?  del(U)   
=======
https://en.wikipedia.org/wiki/First_law_of_thermodynamics
 => First Law of Thermodynamics ( = quasi static process)
U: internal energy

First law of thermodynamics
======================

p10: U = Q  - W;

W : work = P*del(V)
Q :  heat supplied 'to' the sytem ( relation T,S)

differential form : first law of thermodynamics  , 'see above differentation'
====================================

p11:diff(p10);

p11a: del(W) = P*del(V);

? del(Q)     relation with entropy : S
=======

Definition :  Entropy
================
del(Q)/T  = del(S)
https://en.wikipedia.org/wiki/Entropy
see :Classical thermodynamics

p11b: del(Q)/T  = del(S);

p11c: solve(p11b,del(Q))[1];

with use 'p11a,b,c'  into 'p11' 

final: first law of thermodynamics
===========================

p12:lratsubst([p11a,p11c],p11);

?    G=G(T,P)
==========

How to find this :  'plug in  'p7' ' => 'p12','p9'

p13:lratsubst([p9],p7);

p13a:lratsubst([p12],p13);

from mathematics : total differential
============================
dG = ∂G/∂P *del(P) + ∂G/∂T *del(T) 
============================

depends(G,[T,P]);

p14:'diff(G) = diff(G);

How : ('diff(G,T,1)),('diff(G,P,1))  ?
==========================
rem : rhs(p13a) = rhs(p14)

p15: rhs(p14) = rhs(p13a);

new relation between G  and  differentials G
--------------------------------------------------------------
rem : dG = del(G)

p15a:coeff(p15,del(T));
p15b:coeff(p15,del(P));

p15 a : P=cte  for differential G with respect to 'T'
p15b : T= cte  for differential G with respect to 'P'

p15c:p13a;

rem : part '1b' we start with 'p15c'

?  T ,P   = constant
===============

p16a:del(T) = 0;
p16b:del(P) = 0;

p16:subst([p16a,p16b],p15c);

? ideal gas:  P*V = R*T   for  del(G) , n=1 mol
==================================

p17: P*V = R*T;

R: gas constant 
see :https://en.wikipedia.org/wiki/Gas_constant

p17a:declare(R,constant)$

p17b:solve(p17,V)[1];

p17c:subst([p17b],p15c);

When we take : temperature = T =cte
---------------------------------------------------
rem : del(T) = 0

p17d1:del(T) = 0;
p17d2:subst([p17d1],p17c);

mathematics  :  dG  = R*T *dP/P

To  find  G : ideal gas
=================

1e) step : integration : coef  'del(P)'
-------------------------------------------------

p17e1:coeff(rhs(p17d2),del(P));

2e) step : write the integration
-------------------------------------------

p17e2: G = 'integrate(p17e1,P) + const;

3e) integration :  P2 > P > P1
---------------------------------------

assume(P2>P1, P1> 0);

p17e3:G(P2)-G(P1)= integrate(p17e1,P,P1,P2);

rem ,: menu :Simplify: Contract Logarithms

p17e4:logcontract(p17e3);

p17e5:p17e4/(R*T);

p18:solve(p17e5,G(P2))[1];

normalization
===========

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

P1 : 1 atm   => G(P1) = G0  (reference:  by given temperature)
P2: P           => G(P2) = G  ( P= dimensionless)

p18a:[G(P2) =G,G(P1)=G0,P1=1,P2=P];

p18b:subst(p18a,p18);

rem : relation between  R  and boltzmann constant = kb  (Because only Na smaller = const Avogadro)
rem : Na = 6.02 10^23

p18c : Gk = kb*T*log(P) +G0k;

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

rem : How to use integrate
=====================

'integrate(cos(x),x,x1,x2);

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