introductory-chemical-engineering-thermodynamics.ipynb

In [1]:
from sympy import *
from xv.util import listAttr, listProp
In [2]:
U, Q, W, t, S, P, V, F, A, G, T, H, x = symbols('U, Q, W, t, S, P, V, F, A, G, T, H, x')
dU, dQ, dW, dt, dS, dP, dV, dF, dA, dG, dT, dH, dx = symbols('dU, dQ, dW, dt, dS, dP, dV, dF, dA, dG, dT, dH, dx')
C_P, C_V, gamma = symbols('C_P, C_V, gamma')
In [3]:
deltaU, deltaQ, deltaW, deltat, deltaS, deltaP, deltaV, deltaF, deltaA, deltaG, deltaT, deltaH, deltax = symbols('{\Delta}U, {\Delta}Q, {\Delta}W, {\Delta}t, {\Delta}S, {\Delta}P, {\Delta}V, {\Delta}F, {\Delta}A, {\Delta}G, {\Delta}T, {\Delta}H, {\Delta}x')
R, T_1, T_2, P_1, P_2, V_1, V_2 = symbols('R, T_1, T_2, P_1, P_2, V_1, V_2', constant = True)
In [4]:
if not hasattr(Eq, 'Derivative'):
    def _Derivative(self, *variables, **kwargs):
        lhs = Derivative(self.lhs, *variables, **kwargs)
        rhs = Derivative(self.rhs, *variables, **kwargs)
        return Eq(lhs, rhs, evaluate = False)
    print('yes')
    setattr(Eq, 'Derivative', _Derivative)
yes

Closed system

In [5]:
Internal_energy = Eq(U, (Q + W) * t)
Internal_energy
Out[5]:
$\displaystyle U = t \left(Q + W\right)$
In [6]:
Heat_exchange = Eq(Q*dt, T*dS)
Heat_exchange
Out[6]:
$\displaystyle Q dt = T dS$
In [7]:
Work_done = Eq(W*dt, -P*dV)
Work_done
Out[7]:
$\displaystyle W dt = - P dV$
In [8]:
Change_in_U = Eq(dU, T*dS - P*dV)
Change_in_U
Out[8]:
$\displaystyle dU = - P dV + T dS$
In [9]:
Enthalpy = Eq(H, U + P*V)
Enthalpy
Out[9]:
$\displaystyle H = P V + U$
In [10]:
Change_in_H = Eq(dH, dU + V*dP + P*dV)
Change_in_H
Out[10]:
$\displaystyle dH = P dV + V dP + dU$
In [11]:
Change_in_H = Eq(dH, dU + V*dP + P*dV).subs(dU, T*dS - P*dV)
Change_in_H
Out[11]:
$\displaystyle dH = T dS + V dP$
In [12]:
Change_in_A = Eq(dA, -S*dT - P*dV)
Change_in_A
Out[12]:
$\displaystyle dA = - P dV - S dT$
In [13]:
Change_in_G = Eq(dG, -S*dT + V*dP)
Change_in_G
Out[13]:
$\displaystyle dG = - S dT + V dP$
In [14]:
Helmholtz_free_energy = Eq(A, U - T*S)
Helmholtz_free_energy
Out[14]:
$\displaystyle A = - S T + U$
In [15]:
Gibbs_free_energy = Eq(G, H - T*S)
Gibbs_free_energy
Out[15]:
$\displaystyle G = H - S T$
In [16]:
U, H, A, G = symbols('U, H, A, G', cls = Function)
In [17]:
Change_in_U = Eq(dU, Derivative(U(S, V), S) * dS + Derivative(U(S, V), V) * dV)
Change_in_U
Out[17]:
$\displaystyle dU = dS \frac{\partial}{\partial S} U{\left(S,V \right)} + dV \frac{\partial}{\partial V} U{\left(S,V \right)}$
In [18]:
Change_in_U = Eq(dU, Derivative(U(S, V), S) * dS + Derivative(U(S, V), V) * dV).subs(U(S, V), T*S - P*V).doit()
Change_in_U
Out[18]:
$\displaystyle dU = - P dV + T dS$
In [19]:
PDiff_in_U = Eq(Eq(Eq(Derivative(U(S, V), V, S),
                      Derivative(Derivative(T*S - P*V, S).doit(), V)), 
                   Derivative(Derivative(T*S - P*V, V).doit(), S),
                   evaluate = False), 
                Derivative(U(S, V), S, V),
                evaluate = False)
PDiff_in_U
Out[19]:
$\displaystyle \frac{\partial^{2}}{\partial S\partial V} U{\left(S,V \right)} = \frac{d}{d V} T = \frac{d}{d S} \left(- P\right) = \frac{\partial^{2}}{\partial V\partial S} U{\left(S,V \right)}$
In [20]:
Change_in_H = Eq(dH, Derivative(H(S, P), S) * dS + Derivative(H(S, P), P) * dP)
Change_in_H
Out[20]:
$\displaystyle dH = dP \frac{\partial}{\partial P} H{\left(S,P \right)} + dS \frac{\partial}{\partial S} H{\left(S,P \right)}$
In [21]:
Change_in_H = Eq(dH, Derivative(H(S, P), S) * dS + Derivative(H(S, P), P) * dP).subs(H(S, P), T*S + P*V).doit()
Change_in_H
Out[21]:
$\displaystyle dH = T dS + V dP$
In [22]:
PDiff_in_H = Eq(Eq(Eq(Derivative(H(S, P), P, S),
                      Derivative(Derivative(T*S + P*V, S).doit(), P)), 
                   Derivative(Derivative(T*S + P*V, P).doit(), S),
                   evaluate = False), 
                Derivative(H(S, P), S, P),
                evaluate = False)
PDiff_in_H
Out[22]:
$\displaystyle \frac{\partial^{2}}{\partial S\partial P} H{\left(S,P \right)} = \frac{d}{d P} T = \frac{d}{d S} V = \frac{\partial^{2}}{\partial P\partial S} H{\left(S,P \right)}$
In [23]:
Change_in_A = Eq(dA, Derivative(A(T, V), T) * dT + Derivative(A(T, V), V) * dV)
Change_in_A
Out[23]:
$\displaystyle dA = dT \frac{\partial}{\partial T} A{\left(T,V \right)} + dV \frac{\partial}{\partial V} A{\left(T,V \right)}$
In [24]:
Change_in_A = Eq(dA, Derivative(A(T, V), T) * dT + Derivative(A(T, V), V) * dV).subs(A(T, V), - T*S - P*V).doit()
Change_in_A
Out[24]:
$\displaystyle dA = - P dV - S dT$
In [25]:
PDiff_in_A = Eq(Eq(Eq(Derivative(A(T, V), V, T),
                      Derivative(Derivative(- T*S - P*V, V).doit(), T)), 
                   Derivative(Derivative( - T*S - P*V, T).doit(), V),
                   evaluate = False), 
                Derivative(A(T, V), V, T),
                evaluate = False)
PDiff_in_A
Out[25]:
$\displaystyle \frac{\partial^{2}}{\partial T\partial V} A{\left(T,V \right)} = \frac{d}{d T} \left(- P\right) = \frac{d}{d V} \left(- S\right) = \frac{\partial^{2}}{\partial T\partial V} A{\left(T,V \right)}$
In [26]:
Change_in_G = Eq(dG, Derivative(G(T, P), T) * dS + Derivative(G(T, P), P) * dP)
Change_in_G
Out[26]:
$\displaystyle dG = dP \frac{\partial}{\partial P} G{\left(T,P \right)} + dS \frac{\partial}{\partial T} G{\left(T,P \right)}$
In [27]:
Change_in_G = Eq(dG, Derivative(G(T, P), T) * dT + Derivative(G(T, P), P) * dP).subs(G(T, P), - T*S + P*V).doit()
Change_in_G
Out[27]:
$\displaystyle dG = - S dT + V dP$
In [28]:
PDiff_in_G = Eq(Eq(Eq(Derivative(G(T, P), P, T),
                      Derivative(Derivative(- T*S + P*V, T).doit(), P)), 
                   Derivative(Derivative(- T*S + P*V, P).doit(), T),
                   evaluate = False), 
                Derivative(G(T, P), T, P),
                evaluate = False)
PDiff_in_G
Out[28]:
$\displaystyle \frac{\partial^{2}}{\partial T\partial P} G{\left(T,P \right)} = \frac{d}{d P} \left(- S\right) = \frac{d}{d T} V = \frac{\partial^{2}}{\partial P\partial T} G{\left(T,P \right)}$
In [29]:
Change_in_H
Out[29]:
$\displaystyle dH = T dS + V dP$
In [30]:
Change_in_H_const_P = Eq(Derivative(H, T), T*Derivative(S, T), evaluate = False)
Change_in_H_const_P
Out[30]:
$\displaystyle \frac{d}{d T} H = T \frac{d}{d T} S$
In [31]:
Heat_capacity_const_P = Eq(C_P, Derivative(H, T))
Heat_capacity_const_P
Out[31]:
$\displaystyle C_{P} = \frac{d}{d T} H$
In [32]:
Change_in_S_const_P = Eq(Derivative(S, T), C_P / T, evaluate = False)
Change_in_S_const_P
Out[32]:
$\displaystyle \frac{d}{d T} S = \frac{C_{P}}{T}$
In [33]:
S = symbols('S', cls = Function) # Just for partial differential
In [34]:
Change_in_S = Eq(dS, Derivative(S(T, P), T) * dT + Derivative(S(T, P), P) * dP)
Change_in_S
Out[34]:
$\displaystyle dS = dP \frac{\partial}{\partial P} S{\left(T,P \right)} + dT \frac{\partial}{\partial T} S{\left(T,P \right)}$
In [35]:
Change_in_S_const_P = Eq(dS, (C_P / T) * dT + Derivative(-V, T) * dP)
Change_in_S_const_P
Out[35]:
$\displaystyle dS = \frac{C_{P} dT}{T} + dP \frac{d}{d T} \left(- V\right)$
In [36]:
Change_in_S_const_V = Eq(dS, (C_V / T) * dT + Derivative(P, T) * dV)
Change_in_S_const_V
Out[36]:
$\displaystyle dS = \frac{C_{V} dT}{T} + dV \frac{d}{d T} P$
In [37]:
Change_in_H_const_P = Eq(dH, C_P * dT + (V - T*Derivative(V, T)) * dP)
Change_in_H_const_P
Out[37]:
$\displaystyle dH = C_{P} dT + dP \left(- T \frac{d}{d T} V + V\right)$
In [38]:
Change_in_H_const_V = Eq(dH, C_V * dT + (T*Derivative(P, T) - P) * dV)
Change_in_H_const_V
Out[38]:
$\displaystyle dH = C_{V} dT + dV \left(- P + T \frac{d}{d T} P\right)$
In [39]:
Change_in_S = Eq(deltaS, C_P*log(T_2/T_1) - R * log(P_2/P_1))
Change_in_S
Out[39]:
$\displaystyle {\Delta}S = C_{P} \log{\left(\frac{T_{2}}{T_{1}} \right)} - R \log{\left(\frac{P_{2}}{P_{1}} \right)}$
In [40]:
Change_in_S = Eq(0, C_P*log(T_2/T_1) - R * log(P_2/P_1))
Change_in_S
Out[40]:
$\displaystyle 0 = C_{P} \log{\left(\frac{T_{2}}{T_{1}} \right)} - R \log{\left(\frac{P_{2}}{P_{1}} \right)}$
In [41]:
Diff_in_T = Eq(R * log(P_2/P_1), C_P*log(T_2/T_1))
Diff_in_T
Out[41]:
$\displaystyle R \log{\left(\frac{P_{2}}{P_{1}} \right)} = C_{P} \log{\left(\frac{T_{2}}{T_{1}} \right)}$
In [42]:
Diff_in_T = Eq(log(T_2/T_1), logcombine(R*log(P_2/P_1)/C_P, force = True)).simplify()
Diff_in_T
Out[42]:
$\displaystyle \log{\left(\frac{T_{2}}{T_{1}} \right)} = \log{\left(\left(\frac{P_{2}}{P_{1}}\right)^{\frac{R}{C_{P}}} \right)}$
In [43]:
Diff_in_T = Eq(T_2/T_1, (P_2/P_1)**(R/C_P))
Diff_in_T
Out[43]:
$\displaystyle \frac{T_{2}}{T_{1}} = \left(\frac{P_{2}}{P_{1}}\right)^{\frac{R}{C_{P}}}$
In [44]:
Heat_Capacity = Eq(C_P, C_V + R)
Heat_Capacity
Out[44]:
$\displaystyle C_{P} = C_{V} + R$
In [45]:
Diff_in_T = Eq(T_2/T_1, (P_2/P_1)**((C_P - C_V)/C_P))
Diff_in_T
Out[45]:
$\displaystyle \frac{T_{2}}{T_{1}} = \left(\frac{P_{2}}{P_{1}}\right)^{\frac{C_{P} - C_{V}}{C_{P}}}$
In [46]:
Diff_in_T = Eq(Eq(T_2/T_1, P_2*V_2/(P_1*V_1)), (P_2/P_1)**((C_P - C_V)/C_P), evaluate = False)
Diff_in_T
Out[46]:
$\displaystyle \frac{T_{2}}{T_{1}} = \frac{P_{2} V_{2}}{P_{1} V_{1}} = \left(\frac{P_{2}}{P_{1}}\right)^{\frac{C_{P} - C_{V}}{C_{P}}}$
In [ ]:
 

Machine Learning

  1. Deal Banking Marketing Campaign Dataset With Machine Learning

TensorFlow

  1. Difference Between Scalar, Vector, Matrix and Tensor
  2. TensorFlow Deep Learning Model With IRIS Dataset
  3. Sequence to Sequence Learning With Neural Networks To Perform Number Addition
  4. Image Classification Model MobileNet V2 from TensorFlow Hub
  5. Step by Step Intent Recognition With BERT
  6. Sentiment Analysis for Hotel Reviews With NLTK and Keras
  7. Simple Sequence Prediction With LSTM
  8. Image Classification With ResNet50 Model
  9. Predict Amazon Inc Stock Price with Machine Learning
  10. Predict Diabetes With Machine Learning Algorithms
  11. TensorFlow Build Custom Convolutional Neural Network With MNIST Dataset
  12. Deal Banking Marketing Campaign Dataset With Machine Learning

PySpark

  1. How to Parallelize and Distribute Collection in PySpark
  2. Role of StringIndexer and Pipelines in PySpark ML Feature - Part 1
  3. Role of OneHotEncoder and Pipelines in PySpark ML Feature - Part 2
  4. Feature Transformer VectorAssembler in PySpark ML Feature - Part 3
  5. Logistic Regression in PySpark (ML Feature) with Breast Cancer Data Set

PyTorch

  1. Build the Neural Network with PyTorch
  2. Image Classification with PyTorch
  3. Twitter Sentiment Classification In PyTorch
  4. Training an Image Classifier in Pytorch

Natural Language Processing

  1. Spelling Correction Of The Text Data In Natural Language Processing
  2. Handling Text For Machine Learning
  3. Extracting Text From PDF File in Python Using PyPDF2
  4. How to Collect Data Using Twitter API V2 For Natural Language Processing
  5. Converting Text to Features in Natural Language Processing
  6. Extract A Noun Phrase For A Sentence In Natural Language Processing