-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoscillateur.py
52 lines (46 loc) · 1.6 KB
/
oscillateur.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 10 09:05:04 2017
@author: lcharleux
"""
import numpy as np # Clone de Matlab
import matplotlib.pyplot as plt # Librairie graphique
def fonction(x, tau, omega):
"""
Une fonction à tracer.
fonction(1,2,3) = 0.051915149703173388
"""
return np.exp(-x / tau)*np.sin(omega * x)
# Tracé de la fonction
x = np.linspace(0., 10., 1000)
y1 = fonction(x, tau = 5., omega = .5* np.pi)
y2 = fonction(x, tau = 3., omega = 2.* np.pi)
#-------------------------------------------------
# Mise en page plus fine de la figure
from matplotlib import rcParams
plt.rc('text', usetex=True) # Utiliser le c
plt.rc('font', family='serif',
weight='normal', style='normal')
#rcParams['font.serif'] = ['Palatino']
plt.rc('text.latex', preamble =
'''\usepackage[T1]{fontenc}
\usepackage[bitstream-charter]{mathdesign}''')
rcParams['font.size'] = 10
rcParams["xtick.labelsize"] = 10.
rcParams["ytick.labelsize"] = 10.
rcParams['axes.labelsize'] = 10.
#rcParams['title.labelsize'] = 20.
width = 6.69 # Largeur de la figure
heigth = width /2.5 # Hauteur de la figure
#-------------------------------------------------
fig = plt.figure(figsize = (width, heigth))
plt.plot(x, y1, label = r"$\tau = 5, \omega = \pi/2 $")
plt.plot(x, y2, label = r"$\tau = 3, \omega = 2\pi $")
plt.grid()
plt.legend(loc = "best")
plt.xlabel("Temps, $t$")
plt.ylabel("Amplitude, $y(t)$")
plt.title(r"Oscillateur amorti: $y(t) = \exp(-t/\tau)\sin(\omega t)$")
#plt.show()
plt.tight_layout() # Spécifique qu'il faut ajuster la boite pour ne pas mordre sur les labels...
plt.savefig("oscillateur.pdf")