In [1]:
import numpy as np
import pandas as pd
import math
import cmath
from scipy.optimize import root
import matplotlib.pyplot as plt
%matplotlib inline

In [2]:
table = ("Tablea1.txt")
table


Out[2]:
'Tablea1.txt'

In [3]:
class Polynome:
    def __init__(self,table):
        self.table=table
        
    def Lire(self):
        self.abc = pd.read_csv(self.table,sep=" ")
        coef = self.abc.values
        self.a = coef[:,0]
        self.b = coef[:,1]
        self.c = coef[:,2]
        
        print(self.a,self.b,self.c)
        return self.abc 
    
    def calcul(self):
        i = 0
        self.x1 = np.zeros(1)
        self.x2 = np.zeros(1)
        self.x0 = np.zeros(1)
        self.x11 =np.zeros(1)
        self.x12 =np.zeros(1)
                
        print("a : {0},b : {1} et c : {2}".format(self.a,self.b,self.c))
        
        for self.a2, self.b2, self.c2 in zip(self.a,self.b, self.c):
            self.Delta = (self.b**2)-(4 * self.a * self.c)
            print ("Delta = {}".format(self.Delta))
            if self.Delta < 0:
                self.x11 = (-self.b2-cmath.sqrt(self.Delta))/(2*self.a2)
                self.x12 = (-self.b2-cmath.sqrt(self.Delta))/(2*self.a2)
                print ("L'equation a deux solutions : x1 = {0} et x2 ={1}".format(self.x11,self.x12))
            elif self.Delta == 0:
                self.x0 = (-self.b2/(2*self.a2))
                print ("L'equation a une solution: x = {}".format(self.x0))
            else:
                self.x1 = (-self.b2+math.sqrt(self.Delta))/(2*self.a2)
                self.x2 = (-self.b2-math.sqrt(self.Delta))/(2*self.a2)
                print ("L'equation a deux solutions : x1 = {0} et x2 ={1}".format(self.x1,self.x2))
                


    def graphique2(self):
        
        fig,axes=plt.subplots(4,2)
        x = np.linspace(-5,5,100)
        g = (self.a2*x**2)+self.b2*x+self.c2 
    

        for self.a2,self.b2,self.c2 in zip(self.a,self.b,self.c):

            axes[0,0].plot(x,g)
            axes[1,1].plot(x,g)
            axes[0,1].plot(x,g)
            axes[1,0].plot(x,g)

In [7]:
p = Polynome("Table1.txt")
p


Out[7]:
<__main__.Polynome at 0x7fe54fc64828>

In [8]:
p.Lire()


[1 2 3 4 5 6 7 8 9 10] [146 146 146 146 50 146 190 50 146 190] ['EtOH95%' nan nan nan 'EtOH95%' nan nan 'EtOH10%' nan nan]
Out[8]:
Experiment Thickness FoodSimulant Cpo K Dp RMSE k c4
0 1 146 EtOH95% 1157(+/-112) 52.0 1.950000e-13 1.5 0.000007 0.05
1 2 146 NaN 2440(+/-62) 35.0 1.970000e-13 3.0 0.000007 0.05
2 3 146 NaN 3152(+/-40) 24.0 2.000000e-13 2.6 0.000007 0.05
3 4 146 NaN 5950(+/-35) 0.5 2.000000e-13 2.3 0.000007 0.05
4 5 50 EtOH95% 2050(+/-110) 334.0 1.000000e-14 3.1 0.000007 0.05
5 6 146 NaN 2440(+/-62) 35.0 1.970000e-13 3.0 0.000007 0.05
6 7 190 NaN 2878(+/-115) 34.0 2.000000e-13 4.6 0.000007 0.05
7 8 50 EtOH10% 2050(+/-110) 0.0 0.000000e+00 0.0 0.000007 0.05
8 9 146 NaN 2440(+/-62) 0.0 0.000000e+00 0.0 0.000007 0.05
9 10 190 NaN 2878(+/-115) 0.0 0.000000e+00 0.0 0.000007 0.05

In [9]:
p.calcul()


a : [1 2 3 4 5 6 7 8 9 10],b : [146 146 146 146 50 146 190 50 146 190] et c : ['EtOH95%' nan nan nan 'EtOH95%' nan nan 'EtOH10%' nan nan]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-9-f83de2fb7f7c> in <module>()
----> 1 p.calcul()

<ipython-input-3-c8c05230e69d> in calcul(self)
     24 
     25         for self.a2, self.b2, self.c2 in zip(self.a,self.b, self.c):
---> 26             self.Delta = (self.b**2)-(4 * self.a * self.c)
     27             print ("Delta = {}".format(self.Delta))
     28             if self.Delta < 0:

TypeError: unsupported operand type(s) for -: 'int' and 'str'

In [ ]:


In [ ]:


In [ ]: