2012-2013/TD_maple/DS1/test.py

58 lines
1.2 KiB
Python

#!/usr/bin/env python
#-*- coding:utf8-*-
# ------------------------------
# Imports
# ------------------------------
import matplotlib.pyplot as plt
import numpy as np
# ------------------------------
# Classes
# ------------------------------
# ------------------------------
# Fonctions
# ------------------------------
def lissage(L):
""" lissage
"""
D = [0 for l in L]
D[0] = L[0]
for i in range(len(L) - 2):
D[i+1] = sum(L[i:i+3])/3
D[-1] = L[-1]
return D
# ------------------------------
# Bloc principal
# ------------------------------
if __name__ == '__main__':
X = np.linspace(0,1, 20)
A = -320 * X * (X-1) + 25*np.random.random(20)
L = [float(int(A[i]*100))/100 for i in range(len(A))] + np.array([80]*20)
print L
# L = [ 83.68, 103.54, 119.28, 124.75, 136.37, 142.3, 158.33, 157.94, 162.86, 168.11, 162.01, 167.05, 164,149.95, 149.03, 142.29, 124.51, 111.61, 98.7, 87.23]
D = lissage(L)
plt.plot(X,L)
plt.plot(X,D)
plt.show()
# ------------------------------
# Fin du programme
# ------------------------------
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del