from math import log
#Variable Declaration
nb = 5.00 #Number of moles of Benzene, mol
nt = 3.25 #Number of moles of Toluene, mol
T = 298.15 #Temperature, K
P = 1.0 #Pressure, bar
R = 8.314 #Ideal Gas Constant, J/(mol.K)
#Calculations
n = nb + nt
xb = nb/n
xt = 1. - xb
dGmix = n*R*T*(xb*log(xb)+xt*log(xt))
dSmix = -n*R*(xb*log(xb)+xt*log(xt))
#Results
print 'Gibbs energy change of mixing is %4.3e J'%dGmix
print 'Gibbs energy change of mixing is < 0, hence the mixing is spontaneous'
print 'Entropy change of mixing is %4.2f J/K'%dSmix
#Variable Declaration
nb = 5.00 #Number of moles of Benzene, mol
nt = 3.25 #Number of moles of Toluene, mol
T = 298.15 #Temperature, K
R = 8.314 #Ideal Gas Constant, J/(mol.K)
P0b = 96.4 #Vapor pressure of Benzene, torr
P0t = 28.9 #Vapor pressure of Toluene, torr
#Calculations
n = nb + nt
xb = nb/n
xt = 1. - xb
P = xb*P0b + xt*P0t
y = (P0b*P - P0t*P0b)/(P*(P0b-P0t))
yt = 1.-yb
#Results
print 'Total pressure of the vapor is %4.1f torr'%P
print 'Benzene fraction in vapor is %4.3f '%yb
print 'Toulene fraction in vapor is %4.3f '%yt
from sympy import symbols, solve
#Variable Declaration
nb = 5.00 #Number of moles of Benzene, mol
nt = 3.25 #Number of moles of Toluene, mol
T = 298.15 #Temperature, K
R = 8.314 #Ideal Gas Constant, J/(mol.K)
P0b = 96.4 #Vapor pressure of Benzene, torr
P0t = 28.9 #Vapor pressure of Toluene, torr
nv = 1.5 #moles vaporized, mol
#Calculations
n = nb + nt
nl = n - nv
zb = nb/n
x,y, P = symbols('x y P')
e1 = nv*(y-zb)-nl*(zb-x)
print 'Mass Balance:', e1
e2 = P - (x*P0b + (1-x)*P0t)
print 'Pressure and x:',e2
e3 = y - (P0b*P - P0t*P0b)/(P*(P0b-P0t))
print 'Pressure and y:', e3
equations = [e1,e2,e3]
sol = solve(equations)
#Results
for i in sol:
if ((i[x] > 0.0 and i[x] <1.0) and (i[P] > 0.0) and (i[y]>zb and i[y]<1.0)):
print 'Pressure is %4.1f torr' %i[P]
print 'Mole fraction of benzene in liquid phase %4.3f' %i[x]
print 'Mole fraction of benzene in vapor phase %4.3f' %i[y]
#Variable Declaration
m = 4.50 #Mass of substance dissolved, g
ms = 125.0 #Mass of slovent (CCl4), g
TbE = 0.65 #Boiling point elevation, °C
Kf, Kb = 30.0, 4.95 #Constants for freezing point elevation
# and boiling point depression for CCl4, K kg/mol
Msolvent = 153.8 #Molecualr wt of solvent, g/mol
#Calculations
DTf = -Kf*TbE/Kb
Msolute = Kb*m/(ms*1e-3*TbE)
nsolute = m/Msolute
nsolvent = ms/Msolvent
x = 1.0 - nsolute/(nsolute + nsolvent)
#Results
print 'Freezing point depression %5.2f K'%DTf
print 'Molecualr wt of solute %4.1f g/mol'%Msolute
print 'Vapor pressure of solvent is reduced by a factor of %4.3f'%x
#Variable Declaration
csolute = 0.500 #Concentration of solute, g/L
R = 8.206e-2 #Gas constant L.atm/(mol.K)
T = 298.15 #Temperature of the solution, K
#Calculations
pii = csolute*R*T
#Results
print 'Osmotic pressure %4.2f atm'%pii
#Variable Declaration
xCS2 = 0.3502 #Mol fraction of CS2, g/L
pCS2 = 358.3 #Partial pressure of CS2, torr
p0CS2 = 512.3 #Total pressure, torr
#Calculations
alpha = pCS2/p0CS2
gama = alpha/xCS2
#Results
print 'Activity of CS2 %5.4f atm'%alpha
print 'Activity coefficinet of CS2 %5.4f atm'%gama
#Variable Declaration
xCS2 = 0.3502 #Mol fraction of CS2, g/L
pCS2 = 358.3 #Partial pressure of CS2, torr
kHCS2 = 2010. #Total pressure, torr
#Calculations
alpha = pCS2/kHCS2
gama = alpha/xCS2
#Results
print 'Activity of CS2 %5.4f atm'%alpha
print 'Activity coefficinet of CS2 %5.4f atm'%gama
#Variable Declaration
rho = 789.9 #Density of acetone, g/L
n = 1.0 #moles of acetone, mol
M = 58.08 #Molecular wt of acetone, g/mol
kHacetone = 1950 #Henrys law constant, torr
#Calculations
H = n*M*kHacetone/rho
#Results
print 'Henrys constant = %5.2f torr'%H
#Variable Declaration
m = 0.5 #Mass of water, kg
ms = 24.0 #Mass of solute, g
Ms = 241.0 #Molecular wt of solute, g/mol
Tfd = 0.359 #Freezinf point depression, °C or K
kf = 1.86 #Constants for freezing point depression for water, K kg/mol
#Calculations
msolute = ms/(Ms*m)
gama = Tfd/(kf*msolute)
#Results
print 'Activity coefficient = %4.3f'%gama
#Variable Declaration
m = 70.0 #Mass of human body, kg
V = 5.00 #Volume of blood, L
HN2 = 9.04e4 #Henry law constant for N2 solubility in blood, bar
T = 298.0 #Temperature, K
rho = 1.00 #density of blood, kg/L
Mw = 18.02 #Molecualr wt of water, g/mol
X = 80 #Percent of N2 at sea level
p1, p2 = 1.0, 50.0 #Pressures, bar
R = 8.314e-2 #Ideal Gas constant, L.bar/(mol.K)
#Calculations
nN21 = (V*rho*1e3/Mw)*(p1*X/100)/HN2
nN22 = (V*rho*1e3/Mw)*(p2*X/100)/HN2
V = (nN22-nN21)*R*T/p1
#Results
print 'Number of moles of nitrogen in blood at 1 and 50 bar are %3.2e,%3.3f mol'%(nN21,nN22)
print 'Volume of nitrogen released from blood at reduced pressure %4.3f L'%V
from numpy import arange,array,ones,linalg, divide
from matplotlib import pyplot
%matplotlib inline
#Variable Declaration
cCB = array([1e-6,2e-6,3e-6,5e-6,10e-6])
nu = array([0.006,0.012,0.018,0.028,0.052])
y = nu/cCB
print y
xlim(0.0, 0.06)
ylim(5000,6300)
#Calculations
A = array([ nu, ones(size(nu))])
print A
# linearly generated sequence
w = linalg.lstsq(A.T,y)[0] # obtaining the parameters
print 'slope %8.1f'%w[0]
print 'Intercept %8.1f' %w[1]
# Use w[0] and w[1] for your calculations and give good structure to this ipython notebook
# plotting the line
line = w[0]*nu+w[1] # regression line
#Results
plot(nu,line,'r-',nu,y,'o')
xlabel('$ \overline{\upsilon} $')
ylabel('$ \overline{\upsilon}/C_{CB}, M^{-1} $')
#ylabel('$ \dfrac{\overline{\upsilon}}{C_{CB}} $')
show()