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
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]:
In [491]:
p.leer()
Out[491]:
In [495]:
file = "fbao.txt"
file
Out[495]:
In [493]:
p.calcul()
type(p.calcul())
In [480]:
p.Solutions()
In [481]:
p.graphique()
In [464]:
p.addition()
Out[464]:
In [465]:
p.carre()
Out[465]:
In [453]:
tableau = p.copie()
tableau
Out[453]:
In [ ]:
In [ ]:
In [ ]: