In [13]:
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 [224]:
Solutions = {'a': [1],'b': [2], 'c': [3],'x1': [self.x1],'x2': [self.x2]}
df = pd.DataFrame(Solutions, index = ['exp1', 'exp2', 'exp3','exp4','exp5'],columns = ['a', 'b', 'c', 'x1', 'x2'])
df


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-224-d61dfc2df070> in <module>()
----> 1 Solutions = {'a': [1],'b': [2], 'c': [3],'x1': [self.x1],'x2': [self.x2]}
      2 df = pd.DataFrame(Solutions, index = ['exp1', 'exp2', 'exp3','exp4','exp5'],columns = ['a', 'b', 'c', 'x1', 'x2'])
      3 df

NameError: name 'self' is not defined

In [489]:
class Polynôme:
    def __init__ (self,file):
        self.file = file
        
    def leer(self):
        paramètres = pd.read_csv(self.file,sep=" ")
        coefficients = paramètres.values
        self.a = coefficients[:,0]
        self.b = coefficients[:,1]
        self.c = coefficients[:,2]
        print(self.a,self.b,self.c)
        return paramètres
    def calcul(self):
        i = 0
        self.x1 = np.zeros(18)
        self.x2 =np.zeros(18)
        Deltas = (self.b**2)-(4*self.a*self.c)
        print ("Delta = {}".format(Deltas))
        for Delta in Deltas:
            if Delta < 0:
                print("L'equation n'a pas de solutions réelles")
                self.x1i = (-self.b+cmath.sqrt(Delta))/(2*self.a)
                self.x2i = (-self.b-cmath.sqrt(Delta))/(2*self.a)
                print ("L'equation a deux solutions : x1 = {0} et x2 ={1}".format(self.x1,self.x2))
            elif Delta == 0:
                self.xi = (-self.b/(2*self.a))
                print ("L'equation a une solution: x = {}".format(x))
            else:
                self.x1i = (-self.b+math.sqrt(Delta))/(2*self.a)
                self.x2i = (-self.b-math.sqrt(Delta))/(2*self.a)
                print ("L'equation a deux solutions : x1 = {0} et x2 ={1}".format(self.x1,self.x2))
        try:
            d = 1/Delta     
            print("Possible") 
        except ZeroDivisionError:
            print("Division par 0 : impossible") 
        for self.x1i in self.x1:
                self.x1[i]= self.x1 
                print(x1)
        for self.x2i in self.x2:
                self.x2[i] = self.x2
                print(x2)
        return calcul(self)
    def graphique(self):
        x = np.linspace(-5,5,100)
        g = (self.a*x**2)+self.b*x+self.c     
        plt.plot(x,g)
        plt.title("Fonction")
        plt.xlabel("x")
        plt.ylabel("y")
        plt.grid(True)
        plt.annotate("x1",xy=(self.x1,0))
        plt.annotate("x2",xy=(self.x2,0))
    def Solutions(self):
        Solutions2= {'a': [self.a],'b': [self.b], 'c': [self.c],'x1': [self.x1],'x2': [self.x2]}
        self.df = pd.DataFrame(Solutions2, index = ['exp1','exp2','exp3','exp4','exp5'],columns = ['a', 'b', 'c', 'x1', 'x2'])
        self.df
        self.df.to_csv("Polynome2.csv")
    def addition(self):
        self.add = self.x1+self.x2
        return self.add
    def carre(self):
        carre = self.add**2
        return carre
    def copie(self):
        df2 = self.df.copy()
        df2
        return df2

In [494]:
p = Polynôme("fbao.txt")
p


Out[494]:
<__main__.Polynôme at 0x1600130acc0>

In [491]:
p.leer()


[1 2 5 4 7 0 6 8 9] [ 2  3 -2  6 -2  5 -2 -1 -4] [-3 -5 -3 -3 -1 -2 -5 -9 -1]
Out[491]:
a b c
0 1 2 -3
1 2 3 -5
2 5 -2 -3
3 4 6 -3
4 7 -2 -1
5 0 5 -2
6 6 -2 -5
7 8 -1 -9
8 9 -4 -1

In [495]:
file = "fbao.txt"
file


Out[495]:
'fbao.txt'

In [493]:
p.calcul()
type(p.calcul())


Delta = [ 16  49  64  84  32  25 124 289  52]
L'equation a deux solutions : x1 = [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] et x2 =[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
L'equation a deux solutions : x1 = [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] et x2 =[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
L'equation a deux solutions : x1 = [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] et x2 =[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
L'equation a deux solutions : x1 = [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] et x2 =[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
L'equation a deux solutions : x1 = [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] et x2 =[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
L'equation a deux solutions : x1 = [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] et x2 =[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
L'equation a deux solutions : x1 = [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] et x2 =[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
L'equation a deux solutions : x1 = [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] et x2 =[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
L'equation a deux solutions : x1 = [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] et x2 =[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
Possible
C:\Users\Agnès\Anaconda3\lib\site-packages\ipykernel_launcher.py:29: RuntimeWarning: divide by zero encountered in true_divide
C:\Users\Agnès\Anaconda3\lib\site-packages\ipykernel_launcher.py:30: RuntimeWarning: divide by zero encountered in true_divide
C:\Users\Agnès\Anaconda3\lib\site-packages\ipykernel_launcher.py:29: RuntimeWarning: invalid value encountered in true_divide
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-493-0317c0f8b0b2> in <module>()
----> 1 p.calcul()
      2 type(p.calcul())

<ipython-input-489-57aaf2ed9123> in calcul(self)
     36             print("Division par 0 : impossible")
     37         for self.x1i in self.x1:
---> 38                 self.x1[i]= self.x1
     39                 print(x1)
     40         for self.x2i in self.x2:

ValueError: setting an array element with a sequence.

In [480]:
p.Solutions()

In [481]:
p.graphique()


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-481-c45da0440a37> in <module>()
----> 1 p.graphique()

<ipython-input-475-4009ec388011> in graphique(self)
     43     def graphique(self):
     44         x = np.linspace(-5,5,100)
---> 45         g = (self.a*x**2)+self.b*x+self.c
     46         plt.plot(x,g)
     47         plt.title("Fonction")

ValueError: operands could not be broadcast together with shapes (9,) (100,) 

In [464]:
p.addition()


C:\Users\Agnès\Anaconda3\lib\site-packages\ipykernel_launcher.py:51: RuntimeWarning: invalid value encountered in add
Out[464]:
array([-2.        , -1.5       ,  0.4       , -1.5       ,  0.28571429,
               nan,  0.33333333,  0.125     ,  0.44444444])

In [465]:
p.carre()


Out[465]:
array([4.        , 2.25      , 0.16      , 2.25      , 0.08163265,
              nan, 0.11111111, 0.015625  , 0.19753086])

In [453]:
tableau = p.copie()
tableau


Out[453]:
a b c x1 x2
exp1 [1, 2, 5, 4, 7, 0, 6, 8, 9] [2, 3, -2, 6, -2, 5, -2, -1, -4] [3, 5, 3, -3, 1, 2, 5, 9, 1] [(-1+2.23606797749979j), (-0.75+1.118033988749... [(-1-2.23606797749979j), (-0.75-1.118033988749...
exp2 [1, 2, 5, 4, 7, 0, 6, 8, 9] [2, 3, -2, 6, -2, 5, -2, -1, -4] [3, 5, 3, -3, 1, 2, 5, 9, 1] [(-1+2.23606797749979j), (-0.75+1.118033988749... [(-1-2.23606797749979j), (-0.75-1.118033988749...
exp3 [1, 2, 5, 4, 7, 0, 6, 8, 9] [2, 3, -2, 6, -2, 5, -2, -1, -4] [3, 5, 3, -3, 1, 2, 5, 9, 1] [(-1+2.23606797749979j), (-0.75+1.118033988749... [(-1-2.23606797749979j), (-0.75-1.118033988749...
exp4 [1, 2, 5, 4, 7, 0, 6, 8, 9] [2, 3, -2, 6, -2, 5, -2, -1, -4] [3, 5, 3, -3, 1, 2, 5, 9, 1] [(-1+2.23606797749979j), (-0.75+1.118033988749... [(-1-2.23606797749979j), (-0.75-1.118033988749...
exp5 [1, 2, 5, 4, 7, 0, 6, 8, 9] [2, 3, -2, 6, -2, 5, -2, -1, -4] [3, 5, 3, -3, 1, 2, 5, 9, 1] [(-1+2.23606797749979j), (-0.75+1.118033988749... [(-1-2.23606797749979j), (-0.75-1.118033988749...

In [ ]:


In [ ]:


In [ ]: