# -*- coding: utf-8 -*- """ Exercice 1-6 : Sommes partielles d'une série de Fourier Created on Mon May 23 14:11:22 2016 @author: grivet """ import numpy as np import matplotlib.pyplot as plt Pi = np.pi def un(n, x): return (-1)**n*np.cos((2*n+1)*x)/(2*n+1) def sn(N, x): s = 0 # i = 0,1,...,N for i in range(N+1): s += un(i, x) # print(i) return s t = np.linspace(-Pi, 2*Pi, 200) plt.plot(t, sn(3, t),label="n = 3") plt.plot(t, sn(4, t),label="n = 4") plt.plot(t, sn(6, t),label="n = 6") plt.plot(t, sn(10, t),label="n = 10") plt.legend(loc="best")