In [61]:
import numpy as np
import pandas as pd
import math
import cmath
import pickle
from scipy.optimize import root
import matplotlib.pyplot as plt
%matplotlib inline
In [62]:
a = ("Table1.txt")
a
Out[62]:
In [381]:
class InterfazPolimero:
def __init__ (self,a):
self.a=a
def Lire(self):
tab = pd.read_csv(self.a,sep=" ")
coef =tab.values
self.Experiment = coef[:,0]
self.Thickness = coef[:,1]
self.FoodSimulant = coef[:,2]
self.Cpo = coef[:,3]
self.K = coef [:,4]
self.Dp = coef[:,5]
self.RMSE = coef[:,6]
self.k = coef[:,7]
self.c4 = coef[:,8]
# self.c1 =coef[:,9]
self.c2 = np.zeros(10)
return tab
def inicializarC2(self):
self.c2 = np.zeros(10)
self.dimension = np.shape(self.c2)
print(self.dimension)
return self.c2
def calcul(self):
self.j1 = (self.Dp / (self.Thickness / 2)) * (self.Cpo - self.c2)
print(self.j1)
self.c3 = self.c2 / self.K
self.j2 = self.k * (self.c3 - self.c4)
return (self.j1 - self.j2) / self.j1
def calcul2(self):
i = 0
for self.Thickness, self.Dp, self.K, self.k, self.c in enumerate(tab):
self.sol = root(calcul,15,args=(float(self.Dp),float(self.k),float(self.K),float(self.c4),float(self.Cpo),float(self.Thickness)))
c2[i]= self.sol.x
i = i + 1
print(self.c2)
return self.c2
def Garder(self):
raw_data ={"résultat" : [1.115510936772821, 1.0542169426645587, 1.041340418781726, 1.0219,1.4353658536585368, 1.0542169426645587, 1.058921125781793,1.0217682926829268, 1.05340368852459, 1.058921125781793]}
df = pd.DataFrame(raw_data,index=["1","2","3","4","5","6","7","8","9","10"])
df.to_csv("c2rep")
return df
def Graphique(self):
plt.plot(self.Dp,self.Cpo,"^")
plt.title("Cpo=f(Dp)")
def Graphique2(self):
plt.plot(self.Dp,[1.115510936772821, 1.0542169426645587, 1.041340418781726, 1.0219,1.4353658536585368, 1.0542169426645587, 1.058921125781793,1.0217682926829268, 1.05340368852459, 1.058921125781793],"^")
def Graphique3(self):
plt.plot(self.Cpo,[1.115510936772821, 1.0542169426645587, 1.041340418781726, 1.0219,1.4353658536585368, 1.0542169426645587, 1.058921125781793,1.0217682926829268, 1.05340368852459, 1.058921125781793],"^")
In [382]:
p = InterfazPolimero("Table1.txt")
p
Out[382]:
In [383]:
p.Lire()
Out[383]:
In [384]:
p.calcul()
Out[384]:
In [385]:
p.Graphique()
In [386]:
table = p.Garder()
table
Out[386]:
In [387]:
p.Graphique2()
In [388]:
p.Graphique3()
In [ ]:
In [ ]: