from numpy import matrix
# Variables
# Given
P_O = 89 ; # Premium octane -[octane/gal]
S_O = 93 ; # Supereme octane - [octane/gal]
R_O = 87 ; # Regular octane - [octane/gal]
CP = 1.269 ; # Cost of premium octane -[$/gal]
SP = 1.349 ; # Cost of supereme octane -[$/gal]
RP = 1.149 ; # Cost of regular octane -[$/gal]
# Let x and y fraction of regular octane and supreme octane is blended respectively,therefore: x + y = 1 ...(a)
# and 89 = 87x + 93y ...(b)
# Solve equations (a) and (b) simultaneously
# Calculation
a = matrix([[1,1],[87,93]]) ; # Matrix of coefficients of unknown
b = matrix([[1.0],[89.0]]) ; # Matrix of constant
a = a.I
c = a * b
cost = c[0]*RP + c[1]*SP ; # Cost after blending - [$/gal]
sv = CP - cost ; # Save on blending - [$/gal]
# Result
# Check whether there is loss or save
if (sv<0):
print 'We will not save money by blending.'
else:
print 'We will save money by blending, and save is %.3f $/gal.'%sv
# Variables
fd= 1000.0 ; #feed rate-[L/hr]
cfd= 500.0; #Weight of cells per litre- [mg/L]
dn= 1.0 ; #Density of feed-[g/cm**3]
wp= 50.0 ; # Weight percent of cells in product stream
# Calculation and Result
Pg=(fd*cfd*dn)/(1000*wp*.01) ; # Mass balance for cells
print ' Product flow(P) per hour is %.1f g'%Pg
Dg= (fd*dn*1000) - Pg*(wp*.01) ; # Mass balance for the fluid
print ' Discharge flow per hour is %.3e g'%Dg
dn = 0.80 ; #Density of motor oil-[g/cm**3]
# Calculation and Result
in_ms = (10000*(0.1337)*62.4*dn) ; # Initial mass of motor oil in the tank -[lb]
print ' Initial mass of motor oil in the tank is %.1f lb'%in_ms
m_fr = .0015 ; #Mass fractional loss
print ' Mass fractional loss is %.4f '%m_fr
Dsg = m_fr*in_ms ; # Mass balance for the fluid
print ' Discharge of motor oil on flushing flow for 10000 gal motor oil is %.1f lb'%Dsg