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)
In [5]:
Internal_energy = Eq(U, (Q + W) * t)
Internal_energy
Out[5]:
In [6]:
Heat_exchange = Eq(Q*dt, T*dS)
Heat_exchange
Out[6]:
In [7]:
Work_done = Eq(W*dt, -P*dV)
Work_done
Out[7]:
In [8]:
Change_in_U = Eq(dU, T*dS - P*dV)
Change_in_U
Out[8]:
In [9]:
Enthalpy = Eq(H, U + P*V)
Enthalpy
Out[9]:
In [10]:
Change_in_H = Eq(dH, dU + V*dP + P*dV)
Change_in_H
Out[10]:
In [11]:
Change_in_H = Eq(dH, dU + V*dP + P*dV).subs(dU, T*dS - P*dV)
Change_in_H
Out[11]:
In [12]:
Change_in_A = Eq(dA, -S*dT - P*dV)
Change_in_A
Out[12]:
In [13]:
Change_in_G = Eq(dG, -S*dT + V*dP)
Change_in_G
Out[13]:
In [14]:
Helmholtz_free_energy = Eq(A, U - T*S)
Helmholtz_free_energy
Out[14]:
In [15]:
Gibbs_free_energy = Eq(G, H - T*S)
Gibbs_free_energy
Out[15]:
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]:
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]:
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]:
In [20]:
Change_in_H = Eq(dH, Derivative(H(S, P), S) * dS + Derivative(H(S, P), P) * dP)
Change_in_H
Out[20]:
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]:
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]:
In [23]:
Change_in_A = Eq(dA, Derivative(A(T, V), T) * dT + Derivative(A(T, V), V) * dV)
Change_in_A
Out[23]:
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]:
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]:
In [26]:
Change_in_G = Eq(dG, Derivative(G(T, P), T) * dS + Derivative(G(T, P), P) * dP)
Change_in_G
Out[26]:
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]:
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]:
In [29]:
Change_in_H
Out[29]:
In [30]:
Change_in_H_const_P = Eq(Derivative(H, T), T*Derivative(S, T), evaluate = False)
Change_in_H_const_P
Out[30]:
In [31]:
Heat_capacity_const_P = Eq(C_P, Derivative(H, T))
Heat_capacity_const_P
Out[31]:
In [32]:
Change_in_S_const_P = Eq(Derivative(S, T), C_P / T, evaluate = False)
Change_in_S_const_P
Out[32]:
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]:
In [35]:
Change_in_S_const_P = Eq(dS, (C_P / T) * dT + Derivative(-V, T) * dP)
Change_in_S_const_P
Out[35]:
In [36]:
Change_in_S_const_V = Eq(dS, (C_V / T) * dT + Derivative(P, T) * dV)
Change_in_S_const_V
Out[36]:
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]:
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]:
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]:
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]:
In [41]:
Diff_in_T = Eq(R * log(P_2/P_1), C_P*log(T_2/T_1))
Diff_in_T
Out[41]:
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]:
In [43]:
Diff_in_T = Eq(T_2/T_1, (P_2/P_1)**(R/C_P))
Diff_in_T
Out[43]:
In [44]:
Heat_Capacity = Eq(C_P, C_V + R)
Heat_Capacity
Out[44]:
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]:
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]:
In [ ]: