© 2022 Horia Metiu

WorkBookT.5:   Work

Remove["Global`*"] ;
Needs["Utilities`CleanSlate`"];
CleanSlate[];

Cell 1: The work in an isothermal transformation: the ideal gas law

For an ideal gas 
	p(T,v) = R T/v 								(1)
and therefore 
	W=-n (∫_( (Subscript[v, i]))^( (Subscript[v, f]))) pdv=-n (∫_(Subscript[v, i])^(Subscript[v, f]))(R (Subscript[T, i])/v)dv  			(2)
Performing the integral gives

-n Integrate[R (Subscript[T, i])/v,{v,vi,vf},GenerateConditions->False]

The work to change the state of an ideal gas isothermally (T is constant and equal to the initial temperature (Subscript[T, i])) from an initial molar volume (Subscript[v, i]) to a final molar volume (Subscript[v, f]) is 
	  work = - n (Subscript[RT, i]) ln{((Subscript[v, f])/(Subscript[v, i]))}						(3)
As the temperature is held constant and the volume changes, the pressure must change. The initial pressure is 
	(Subscript[p, i]) = R (Subscript[T, i])/(Subscript[v, i])  and  (Subscript[p, f]) = R (Subscript[T, f])/(Subscript[v, f])					(4)
Combining Eq. 3 with Eq. 4 gives:
	work = - n R (Subscript[T, i]) ln{((Subscript[p, i])/(Subscript[p, f]))}							(5)
To get the  work in Joule use R = 8.3145 J

Cell 2: Isothermal work using the van der Waals equation of state

For an isothermal transformation of a gas with the van der Waals equation of state:
W =  -n (∫_( (Subscript[v, i]))^( (Subscript[v, f])))p((Subscript[T, i]),v)dv  = -n (∫_( (Subscript[v, i]))^( (Subscript[v, f]))){ R (Subscript[T, i])/(v-b) -a/(v^2)}dv				(1)
Perform the integral:

Clear[a,b,vi,vf]
-n Integrate[R Ti/(v-b)-a/v^2,{v,vi,vf},GenerateConditions->False]

The result is 
	W/n = a {(1/(Subscript[v, i])) - (1/(Subscript[v, f]))} + R (Subscript[T, i]) ln{(((Subscript[v, f ])- b)/((Subscript[v, i]) -b))}
If you use a in units of atm (liter^2)/(mol^2) and b in liter/mole then you must use 
	R = 0.082  liter atm/mol K. 
To get the work in Joules, convert liter atm (which is a unit of energy) into Joules.  From  Appendix 7 
	1.0 liter atm = 101.325 J = 24.2173 cal

Cell 3: ★ The work in an isothermal transformation: numerical calculations

Cell 3.1: Formulate the problem and the solution

Calculate how much work it takes to compress one mole of  (Subscript[CO, 2])  from p = 1 atm to p = 100 atm at a constant temperature T = 350 K. Perform two calculations: one using the ideal gas law and the other using the Beattie-Bridgeman equation. Compare the results.

Plan for solving the problem: 
• I must perform the integral in  
		W = - n(∫_( (Subscript[v, i]))^( (Subscript[v, f])))p(350,v)dv 					(1)
• I calculate the initial and final molar volumes (Subscript[v, i]) and (Subscript[v, f]), by solving the equations
		1 atm=f(T=350,(Subscript[v, i])) 						(2)
 and
		10  atm=f(T=350,(Subscript[v, f]))						(3)
• Because the transformation is isothermal, T = 350 K in these equations. 
• f (T,v) is the equation of state.
•  I calculate the integral in Eq. (1) numerically.

Cell 3.2: The calculation for an ideal gas

• Calculate the integral giving the work for one mole  (n =1):
	W= - (∫_(Subscript[v, i])^(Subscript[v, f]))p((Subscript[T, i]),v)dv = - (∫_(Subscript[v, i])^(Subscript[v, f]))(R (Subscript[T, i])/v)dv = - R (Subscript[T, i]) ln (((Subscript[v, f])/(Subscript[v, i])))		(1)
• I use R = 8.31 Joule /mol K (Appendix 3) to get the work in Joule.   
• The temperature (Subscript[T, i])  is constant and equal to 350 K.   
• The initial and final molar volumes are  
	(Subscript[v, i]) = R (Subscript[T, i])/(Subscript[p, i])  and (Subscript[v, f]) = R (Subscript[T, i])/(Subscript[p, f])			(2)
• Using Eq. (2) in Eq. (1) gives
	W= - R (Subscript[T, i]) ln (((Subscript[v, f])/(Subscript[v, i]))) = - R T ln (((Subscript[p, i])/(Subscript[p, f])))		(3)
• The final pressure is 100 atm, the initial one is 1 atm. Therefore the work is (in Joule) 
	W = - 8.3145*350*ln ((1/100))

workIdeal= - 8.3145*350*Log[1/100](*Joule*)

Cell 3.3: ★ Define the pressure according to Beattie-Bridgeman.

This calculation is complicated mostly because I was given the initial and final pressures, and for calculating the work I need the initial and the final molar volumes. To calculate the molar volumes I must solve
	(Subscript[p, i]) = f((Subscript[T, i]),(Subscript[v, i]))   and   (Subscript[p, f]) = f((Subscript[T, i]),(Subscript[v, f]))
where f (T,v) = p is the equation of state.  If I use the Beattie-Bridgeman equation I can only solve for the volumes  numerically.

Define the function pBB[T, v, parameters] to calculate the pressure from the Beattie-Bridgeman equation :
	 p = f(T,v) = ((R T)/(v^2)) (1 -  (c/(v (T^3)))) (v +B-((b B)/v)) -   (A/(v^2))(1-(a/v))

Clear[pBB]
pBB[T_(*liter/mol*),v_(*liter/mol*),parameters_]:=Module[
{ R=0.08205(*liter atm/mol K*),p1,p2,p3},
     Clear[A,a,B,b,c] ;  
    p1=1-c/(v T^3);
    p2=v+B-b B/v;
    p3=A*(1-a/v);
   ( (R T p1 p2-p3)/v^2)/.parameters (*p in atm*)];
SetAttributes[pBB,HoldAll];

The parameters for the Beattie-Bridgeman equation of state for (Subscript[CO, 2]) are (Appendix 5)

Clear[A,B,a,b,c]
paramBB={A->5.0065,a->0.07132,B->0.104760,
 b->0.072350, c->66.0000*10^4};

Check that the function PBB works:

pBB[298,22,paramBB]

This is the right order of magnitude.

Cell 3.4: ★ Calculate the molar volume in the initial and the final state

In the previous WorkBook I define the function volumeG[T, p, f, parameter] which when given the temperature T, the pressure p, the equation of state  p = f(T, v) and the parameters of the equation of state, will calculate the molar volume.

volumeG[T_,p_,f_,parameters_]:=
	Module[{R=0.082 (*liter atm/mol*),eq,sol},
Clear[a,b,c,A,B,C0,γ];
	eq=p==f[T,v ,parameters];
		v/.FindRoot[eq,{v,R T/p}] ];

Use volumeG to calculate the molar volume at 350 K and p = 1 atm (the initial state), and at 350 K and p = 100 atm (the final state)

volumeG[350,1,pBB,paramBB]

Calculate the initial and the final volumes

Clear[vi,vf]
rulesVol={vi->volumeG[350,1,pBB, paramBB],vf->volumeG[350,100,pBB, paramBB]}

The output contains replacement rules for vi and vf.

Cell 3.5: ★ Calculate the work with the Beattie-Bridgeman equation

I must perform the integral 
	W = - (∫_( (Subscript[v, i]))^( (Subscript[v, f]))) p(T,v)dv 
with p(T,v) given by the Beattie-Bridgeman equation. Since p is in atm and v in liter/mol, I obtain the work in liter atm. I convert this to Joules. The conversion factor is 101.325 (Appendix  7).

workBB=-101.325 Integrate[pBB[350,v,paramBB],{v,vi,vf}/.rulesVol] (*Joule*)

Cell 3.6:  Is ideal gas law accurate?

The calculation using the ideal gas law gave 13401.4 J.  The percent difference is

(workBB-workIdeal)*100/workBB

The ideal gas law underestimates the energy you need by 0.41 %.  It is surprisingly good as far as calculating work is concerned.  However, if you want accurate results, especially at low T and high p you should use the Benedict-Webb-Rubin equation.

Cell 4: ★ The work produced during a constant-pressure transformation

Cell 4.1.  State the problem and the plan for solving it

Calculate the work exchanged between the system and the environment when you heat up two moles of CO from 298 K to 1000 K, at a constant pressure of 100 atm.  Use the van der  Waals equation of state.

Plan for solving the problem:   
• The transformation is 
	(Subscript[σ, i])= { 298 K, 100 atm} -> (Subscript[σ, f]) = {1000 K, 100 atm}
• The work produced by an isobaric transformation is (see Eq. 5.17):
	W = – n (Subscript[p, i]) (vf – (Subscript[v, i])) = - n 100  (vf – (Subscript[v, i]))	 	(1)	 
• To calculate W  I need to know the initial and final molar volumes (Subscript[v, i]) and (Subscript[v, f]).  I  calculate them by using van der Waals equation 
 	100= R 298 /( (Subscript[v, i]) –b) – a/(Subscript[v, i]^2)					(2)
  for (Subscript[v, i]) and 
  	 100= R 1000 /( (Subscript[v, f]) –b) –a/(Subscript[v, f]^2)					(3)
   for (Subscript[v, f])  (I know the magnitude of (Subscript[p, i]), (Subscript[p, f]) and (Subscript[T, i]))
• Eq. (1) gives the work in  liter atm. I convert it to joules by using the conversion factor 1 liter atm = 101.311 J, given in Appendix 9 .

Cell 4.2:  Define the van der Waals equation for CO

The van der Waals equation is 
	p = ((R T)/((v-b))) - (a/(v^2)) 
The parameters a and b in the van der Waals equation for CO are  given below (values taken from Appendix 4).

pvdw[T_,p_,parameters_]:=With[{R = 0.08205 (*liter atm/mole K*)},
R T/(v-b)-a/v^2/.parameters]

pvdw[T,p,{}]

Clear[a,b]
paramvdw={a->1.48543 (*liter^2 atm/mol^2*),b->0.03985 (*liter/mol*)}

Test that the function giving the van der Waals pressure works:

{pvdw[T,v,paramvdw],pvdw[T,v,{}]}

Cell 4:3:  Calculate the molar volume in the initial and the final state

volumeG[T_,p_,f_,parameters_]:=
	Module[{R=0.082 (*liter atm/mol*),eq,sol},
Clear[a,b,c,A,B,C0,γ];
	eq=p==f[T,v ,parameters];
		v/.FindRoot[eq,{v,R T/p}] ];

rulesVol={vi->volumeG[298,100,pvdw,paramvdw],vf->volumeG[1000,100,pvdw,paramvdw]}

This gives the molar volumes in liter/mol.

Cell 4:4:  Calculate the work

For an isobaric transformation the work is 
	W = -n (Subscript[p, i]) ( (Subscript[v, f])-(Subscript[v, i]))
Using the pressure in atm and the molar volume in liter/mole, this gives the work in liter atm. To convert to joules, multiply with 101.311. There are two moles so n = 2

W=- 101.325*2 (vf-vi)/.rulesVol

During the transformation the system produces work. This is what one expect because an increase of the volume moves the piston upwards producing work.

Cell 5: ★ Work depends on path

Cell 5.1:  Formulate the problem and explain how you find the solution

I want to calculate the work performed in  two transformations, called A and B, that have the same initial and final states but go on different paths. The initial state is
 	 (Subscript[σ, i]) = {(Subscript[p, i]) = 1 atm, (Subscript[T, i]) = 298 K}					(1)
 and  final state  is
 	 (Subscript[σ, f]) = {(Subscript[p, f])  = 10 atm, (Subscript[T, f]) = 650 K}. 			(2)

The two path are described by the diagram

Path A:  The path of transformation A is a superposition of two paths named AI and AII

Path AI:  The transformation is: 
 	(Subscript[σ, i]) = {(Subscript[p, i])  = 1 atm, (Subscript[T, i]) = 298 K} ⟶  
 	(Subscript[σ, 1])= {(Subscript[p, f])  = 10 atm, (Subscript[T, i]) = 298 K}    		(3)
The work along this isothermal path, for one mole of substance, is:
	WAI= (∫_(Subscript[v, i])^(Subscript[v, 1]))p((Subscript[T, i])=298,v)dv				(4)
Here (Subscript[v, 1 ])is the molar volume in state (Subscript[σ, 1])and (Subscript[v, i]) is the molar volume in the initial state  (Subscript[σ, i])

Path AII:  Is
	(Subscript[σ, 1]) = {(Subscript[p, f])  = 10 atm, (Subscript[T, i]) = 298 K} ⟶ 
	(Subscript[σ, f])= {(Subscript[p, f])  = 10 atm, (Subscript[T, f]) = 650 K} 			(5)
This is an isobaric raise of temperature.  For a mole of substance the  work along this path is 
	WAII =  - (Subscript[p, f]) ((Subscript[v, f]) - (Subscript[v, i]))  					(6)
where (Subscript[v, f]) is the molar volume in state (Subscript[σ, f]) and (Subscript[p, f]) = 10 atm

Path A: The work along the path A is 
	WA = WAI + WAII					(7)

Path B:  The path of transformation B consists of two segments.

Path BI:  Is the isobaric transformation
	(Subscript[σ, i]) = {p = 1 atm, T = 298 K}⟶
	(Subscript[σ, 2]) = {p = 1 atm, T= 650 K}					(8)
The work along this isobaric path is
	WBI = - (Subscript[p, i])((Subscript[v, 2]) -(Subscript[v, i]) )						(9)

Path BII:  Is represented by 
	(Subscript[σ, 2]) = {(Subscript[p, i]) = 1 atm, (Subscript[T, f]) = 650 K} →
	(Subscript[σ, f]) = {(Subscript[p, f]) = 10 atm, (Subscript[T, f]) = 650K}
The work along this path is
	WBII = - (∫_( (Subscript[v, 2]))^(Subscript[v, f])) p(T=650,v)dv
and (Subscript[v, 2]) is the volume in state (Subscript[σ, 2]) and (Subscript[v, f]) is the volume in state (Subscript[σ, f])

The work along path B is 
	WB = WBI + WBII

I want to calculate the work for the two transformations described by paths A and B, for one mole of CO.  I will use the van der Waals equation of state (see Chapter 2) which  describes the behavior of the system well in this pressure and temperature range. The parameters a and b in the van der Waals equation are (from Appendix 4)  
	a = 1.48500 × 0.987 liter2atm/(mol^2) and  b = 0.0398 liter/mol.

Cell 5.2:  Define the van der Waals equation

pvdw[T_,v_,parameters_]:=With[{R = 0.08206 (*liter atm/mole K*)},
R T/(v-b)-a/v^2/.parameters]

Get the van der Waals parameters for CO

Clear[a,b]
paramvdw={a->1.485 (*liter^2 atm/mol^2*),b->0.03985 (*liter/mol*)}

Test that the function pvdw works properly

{pvdw[T,v,{}],pvdw[T,v,paramvdw]}

Cell 5.3: Calculate the molar volumes (Subscript[v, i]), (Subscript[v, f]), (Subscript[v, 1]) and (Subscript[v, 2])

Four states, (Subscript[σ, i]), (Subscript[σ, 1]), (Subscript[σ, 2]), and (Subscript[σ, f]), are involved in these transformations.  The molar volumes in these states will be denoted by (Subscript[v, i]), (Subscript[v, 1]), (Subscript[v, 2]), and (Subscript[v, f]), respectively. To calculate the work I need to know the magnitude of these volumes.  I use the equation of state to calculate them (see Chapter 3 and WorkBookT.3).

Calculate the molar volumes using the function VolumeG and the van der Waals equation for (Subscript[CO, 2])

volumeG[T_,p_,f_,parameters_]:=
	Module[{R=0.082 (*liter atm/mol*),eq,sol},
Clear[a,b,c,A,B,C0,γ];
	eq=p==f[T,v ,parameters];
		v/.FindRoot[eq,{v,R T/p}] ];

Clear[vi,v1,v2,vf];	volumeRules={vi-> volumeG[298,1,pvdw,paramvdw],v1-> volumeG[298,10,pvdw,paramvdw],v2-> volumeG[650,1,pvdw,paramvdw],vf-> volumeG[650,10,pvdw,paramvdw]} (*liter/mole*)

Cell 5.4: Calculate the work along the path A

Path A goes from
	 (Subscript[σ, i])={1 atm, 298 K} to (Subscript[σ, 1]) ={10 atm, 298 K}  
and then from
	 (Subscript[σ, 1]) to (Subscript[σ, f])= {10 atm , 650 K} (the segment AII).  
The work along path A is (use Eqs.  4, 6, 7) : 
WA = WAI + WAII = -(∫_(Subscript[v, i])^(Subscript[v, 1]))p(T=298,v) dv - (∫_(Subscript[v, 1])^(Subscript[v, f]))10 dv		
The first integral is for the work of the transformation along isothermal path AI,  and the second is along isobaric path AII. The result is in liter atm (if v is in liter/mol and p in atm). I need to convert the work to joules by using 
	1 liter atm = 101.325 J  (see Appendix 7)

Clear[v]
WAI=101.325*(-Integrate[pvdw[298,v,paramvdw],{v,vi,v1},GenerateConditions->False])/.volumeRules

Calculate the work along path AII:

WAII=101.325*(-Integrate[10,{v,v1,vf}])/.volumeRules

The work along path AI is positive, which means that the environment exerts work on the system. This is not surprising:  in going from (Subscript[σ, i]) to (Subscript[σ, 1]) I compress the system from (Subscript[v, i]) = 24.432 liter/mol to (Subscript[v, 1]) = 2.425 liter/mol. The work along path AII is negative. The system is heated and the volume expands from (Subscript[v, 1]) = 2.425 liter to (Subscript[v, f]) = 5.346 liter. Thus the system exerts work on the environment (it  lifts up the weights on the piston).

The work along path A is the sum of WAI and WAII

WA=WAI+WAII

The work along path A is positive: the environment exerts work on the system. The work we did to compress the system is larger than the work we recovered when we heated it.

Cell 5.5: Calculate the work on path B

Path B has two segments, BI and BII.  The transformation BI is the isobaric (constant pressure) transformation
 	(Subscript[σ, i])={p = 1 atm,T = 298 K} ⟶ 
 	(Subscript[σ, 2])={ p = 1 atm, T = 650 K}.   
The work in this isobaric  transformation is:
	(Subscript[W, I]) = -(Subscript[p, i]) ( (Subscript[v, 2])-(Subscript[v, i]))						(12)
Path BII is the isothermal transformation 
	(Subscript[σ, 2]) = { p = 1 atm, T = 650 K} ⟶ 
	(Subscript[σ, f]) = { p = 10 atm, T = 650 K}.  
The isothermal work on path  BII is  
	(Subscript[W, II]) = (∫_(Subscript[v, 2])^( (Subscript[v, f])))p(650,v)dv					(13)
Here (Subscript[p, i]) = 1 atm, and (Subscript[v, 2]), (Subscript[v, i]) and (Subscript[v, f]) are the molar volumes in the states (Subscript[σ, i]),(Subscript[σ, 2]), and (Subscript[σ, f]). We have already calculated these volumes.

The work on the path BI is -(Subscript[p, i])( (Subscript[v, 2]) -(Subscript[v, i])).  This gives the result in atm liter/mol. I convert this to joules by multiplying with 101.325 (See Appendix 7).

WBI=-101.325* Integrate[1 ,{v,vi,v2}]/.volumeRules

The result is negative because the system exerts work on the environment (the weights are lifted).

Along path BII the system goes from the state (Subscript[σ, 2]) to state (Subscript[σ, f]) by keeping the temperature constant at 650 K and increasing the pressure from 1 to 10 atm. The work is 
	WII = - (∫_(Subscript[v, 2])^(Subscript[v, f]))p(650,v)dv 
and needs to be converted to joules

WBII=-101.325*Integrate[pvdw[650,v,paramvdw],{v,v2,vf}, GenerateConditions->False]/.volumeRules

This work along this path is positive since we increase the pressure by putting more weights on the piston. The gas is compressed and the environment does work on the system.

The work along path B is 
	WB = WBI + WBII:

WB=WBI+WBII

Cell 5.6:  Compare the work on the two paths:

WA

WB

They are very different. The work definitely depends on the path.