/home/myriam/Desktop/préparation À l`oral/seances
Transcription
/home/myriam/Desktop/préparation À l`oral/seances
""" EXERCICE TYPE n°1 """ #question 1 """ voici une première solution """ fichier=open('ex_001.csv',mode='r') data=fichier.read() fichier.close() print(data) print(type(data)) #data est une chaine de caractere, inexploitable """ première solution : collecter les données ligne par ligne """ fichier=open('ex_001.csv',mode='r') LX=[] LY=[] for ligne in fichier: donnee=ligne.split(';') LX.append(float(donnee[0])) LY.append(float(donnee[1])) fichier.close() print(LX) print(LY) """ deuxième solution : créer un tableau numpy """ import numpy as np data2=np.genfromtxt('ex_001.csv',delimiter=';') LX2=data2[:,0] #première colonne du tableau LY2=data2[:,1] # deuxième colonne du tableau print(LX2) print(LY2) #question 2 import matplotlib.pyplot as plt plt.figure() plt.plot(LX,LY,marker='o') plt.show() #question 3 def trapeze(x,y): 1 assert len(x)==len(y) s=0 for k in range(1,len(x)): s+=(x[k]-x[k-1])*(y[k]+y[k-1])/2. return s I=trapeze(LX,LY) print(I) #question 4 import scipy.integrate as sci I2=sci.trapz(LY,LX) print(I2) 2