-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCours 12.py
More file actions
140 lines (123 loc) · 3.67 KB
/
Copy pathCours 12.py
File metadata and controls
140 lines (123 loc) · 3.67 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import matplotlib.pyplot as plt
import numpy as np
import math as m
x = np.linspace(-2, 2, 101)
y = x ** 2
plt.plot(x, y)
plt.show()
x = np.linspace(0, 3 * np.pi, 500)
plt.plot(x, np.sin(x**2))
plt.title("A simple chirp")
plt.show()
x = np.linspace(-2, 2, 101)
y = x ** 2
plt.plot(y)
plt.show()
x = np.linspace(-2, 2, 101)
y = x ** 2
plt.xlabel("x")
plt.ylabel("f(x)")
plt.xlim(-1.5, 1.5)
plt.ylim(-0.5, 2.5)
plt.title("Chart title")
plt.plot(x, y)
plt.show()
x = np.linspace(-2, 2, 101)
y = x ** 2
plt.plot(x, y, label="x ** 2")
y = x
plt.plot(x, y, label="x")
plt.legend()
plt.show()
plt.savefig("fig.png")
x = np.linspace(-1, 1, int(input("Combien de points voulez-vous afficher ? ")))
y = np.cos(2 * np.pi * x)
plt.xlabel("x")
plt.ylabel("y = cos(2 * pi * x)")
plt.xlim(-1, 1)
plt.ylim(-1, 1)
plt.title("Body function(2 * pi * x)")
plt.plot(x, y)
plt.show()
plt.savefig("cos2pix.png")
x = np.linspace(-1, 1, int(input("Combien de points voulez-vous afficher ? ")))
y = np.cos(2 * np.pi * x)
plt.plot(x, y, "b", label="cos")
y = np.sin(2 * np.pi * x)
plt.plot(x, y, "r", label="sin")
plt.xlabel("x")
plt.ylabel("y = cos(2 * pi * x)")
plt.xlim(-1, 1)
plt.ylim(-1, 1)
plt.title("Body function(2 * pi * x)")
plt.legend()
plt.show()
x = np.linspace(0, 4, int(input("Combien de points voulez-vous afficher ? ")))
y = np.sin(np.pi * x) * np.sin(20 * np.pi * x) * np.exp(-x)
plt.plot(x, y, "b")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.xlim(0, 4)
plt.title("Graph")
plt.show()
temp = int(input("Quelle est la température du gaz ? "))
x = np.linspace(2, 10, int(input("Combien de points voulez-vous afficher ? ")))
y = 0.008206 * temp/x
plt.plot(x, y)
plt.xlabel("V (L)")
plt.ylabel("P (hPa)")
plt.title("Isotherm (ideal gas)")
plt.show()
plt.savefig("isotherm.png")
n = int(input("Quel est le nombre de température ? "))
a = int(input("Combien de points voulez-vous afficher ? "))
for i in range(n):
temp = int(input("Quelle est la température du gaz ? "))
x = np.linspace(2, 10, a)
y = 0.008206 * temp/x
plt.plot(x, y)
plt.xlabel("V (L)")
plt.ylabel("P (hPa)")
plt.title("Isotherm (ideal gas)")
plt.show()
plt.savefig("isotherm.png")
x0 = float(input("Quelle est la valeur de x0 ? "))
s = float(input("Quelle est la valeur de s ? "))
xstart = int(input("Quelle est la première valeur de l'intervalle ? "))
xend = int(input("Quelle est la dernière valeur de l'intervalle ? "))
n = int(input("Quelle est le nombre de points à afficher ? "))
x = np.linspace(xstart, xend, n)
y = 1/m.sqrt(2 * np.pi) * np.exp(-1/2 * (x - x0) ** 2/s ** 2)
plt.plot(x, y)
plt.xlabel("x")
plt.ylabel("f(x)")
plt.xlim(xstart, xend)
plt.title("Gaussian fonction")
plt.show()
x = np.linspace(0, 3, 100)
y = np.exp(-x)
plt.plot(x, y, label="exp(-x)")
y = np.sin(3 * np.pi * x) * np.exp(-x)
plt.plot(x, y, label="sin(3 * pi * x) * exp(-x)")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.xlim(0, 3)
plt.ylim(-0.6, 1)
plt.title("Fonctions")
plt.legend()
plt.show()
c = int(input("Quelle est le nombre de courbes de Gauss à afficher ? "))
xstart = int(input("Quelle est la première valeur de l'intervalle ? "))
xend = int(input("Quelle est la dernière valeur de l'intervalle ? "))
n = int(input("Quelle est le nombre de points à afficher ? "))
x = np.linspace(xstart, xend, n)
for i in range(c):
x0 = float(input("Quelle est la valeur de x0 ? "))
s = float(input("Quelle est la valeur de s ? "))
y = 1/m.sqrt(2 * np.pi) * np.exp(-1/2 * (x - x0) ** 2/s ** 2)
plt.plot(x, y, label=f"x0 = {x0} et s = {s}")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.xlim(xstart, xend)
plt.title("Gaussian fonction")
plt.show()