Skip to content

Instantly share code, notes, and snippets.

@santiago-salas-v
Created April 24, 2019 20:10
Show Gist options
  • Save santiago-salas-v/068577a09dcb8234870dd4c284b8b036 to your computer and use it in GitHub Desktop.
Save santiago-salas-v/068577a09dcb8234870dd4c284b8b036 to your computer and use it in GitHub Desktop.
Permeability of a polymer film
from numpy import array, ones
from numpy.linalg import inv
import matplotlib.pyplot as plt
# Ref. E. L Cussler - Diffusion mass transfer in fluid systems 2009
m = array([14])
text_data = """
0 14.0153
1 13.9855
4 13.9104
7 13.8156
8 13.7710
12 13.6492
14 13.5830
16 13.5256
"""
t,m = array(
[x.split(' ') for x in text_data.split('\n') if len(x)>0],
dtype=float
).T
plt.plot(t,m,'o')
h = array([t,ones(len(t))]).T
y = inv(h.T.dot(h)).dot(h.T).dot(m)
sstot=(m-sum(m)/len(m)).dot((m-sum(m)/len(m)))
eTe =(m - h.dot(y)).dot((m - h.dot(y)))
r2 = 1-eTe/sstot
plt.plot(t, h.dot(y),
'-', color='gray',
label='{:0.4g}(g/d) t + {:0.4g}g '.format(*y)+
r'$R^2={:0.4g}$'.format(r2))
plt.xlabel('t / d')
plt.ylabel('m / g')
plt.legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment