-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule-MATH.py
More file actions
356 lines (245 loc) · 6.01 KB
/
Module-MATH.py
File metadata and controls
356 lines (245 loc) · 6.01 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
########## MATH MODULE ##########
https://docs.python.org/fr/3.13/library/math.html
# MATH module comes with the standard Python release, and contains some useful constants and functions for carrying out mathematical operations
# Note: all trigonometrical functions take their arguments expressed in radians
import math
### constants
math.pi # Pi, the ratio of the circumference of a circle to its diameter 3.141592653589793
math.e # Euler's number, the base of natural logarithms 2.718281828459045
math.tau # Tau, the ratio of a circle's circumference to its radius (2 * pi) 6.283185307179586
math.inf # Positive infinity float('inf')
math.nan # Not-a-Number (NaN) float('nan')
### Racine carrée
## math.sqrt(x)
# racine carrée de x, en float
print(math.sqrt(16))
# 4.0
print(math.sqrt(25))
# 5.0
print(math.sqrt(2))
# 1.4142135623730951
### fonctions trigonométriques de base
## math.sin(x)
# sine of x
print(math.sin(0))
# 0.0
print(math.sin(math.pi/2))
# 1.0 (90 degrés)
## math.cos(x)
# cosine of x
print(math.cos(0))
# 1.0
print(math.cos(math.pi))
# -1.0 (180 degrés)
## math.tan(x)
# the tangent of x
print(math.tan(0))
# 0.0
print(math.tan(math.pi/4))
# 1.0 (45 degrés)
### fonctions trigonométriques inverses
## math.asin(x)
# arcsine of x
print(math.asin(0))
# 0.0
print(math.asin(1))
# 1.5707963267948966 (π/2)
## math.acos(x)
# arccosine of x
print(math.acos(1))
# 0.0
print(math.acos(0))
# 1.5707963267948966 (π/2)
## math.atan(x)
# arctangent of x
print(math.atan(0))
# 0.0
print(math.atan(1))
# 0.7853981633974483 (π/4)
### conversions degrés/radians
## math.radians(x)
# convertit degrés en radians
print(math.radians(90))
# 1.5707963267948966 (π/2)
print(math.radians(180))
# 3.141592653589793 (π)
print(math.radians(360))
# 6.283185307179586 (2π)
## math.degrees(x)
# convertit radians en degrés
print(math.degrees(math.pi))
# 180.0
print(math.degrees(math.pi/2))
# 90.0
### Fonctions hyperboliques
## math.sinh(x)
# hyperbolic sine
print(math.sinh(0))
# 0.0
print(math.sinh(1))
# 1.1752011936438014
## math.cosh(x)
# hyperbolic cosine
print(math.cosh(0))
# 1.0
print(math.cosh(1))
# 1.5430806348152437
## math.tanh(x)
# hyperbolic tangent
print(math.tanh(0))
# 0.0
print(math.tanh(1))
# 0.7615941559557649
### Fonctions hyperboliques inverses
## math.asinh(x)
# hyperbolic arcsine
print(math.asinh(0))
# 0.0
print(math.asinh(1))
# 0.8813735870195429
## math.acosh(x)
# hyperbolic arccosine
# (x ≥ 1)
print(math.acosh(1))
# 0.0
print(math.acosh(2))
# 1.3169578969248166
## math.atanh(x)
# hyperbolic arctangent
# (-1 < x < 1)
print(math.atanh(0))
# 0.0
print(math.atanh(0.5))
# 0
### Fonction exponentielle
## math.exp(x)
# finds the value of ex
print(math.exp(0))
# 1.0 (e^0)
print(math.exp(1))
# 2.718281828459045 (e^1 = e)
print(math.exp(2))
# 7.38905609893065 (e^2)
print(math.exp(-1))
# 0.36787944117144233 (e^-1)
## math.pow(x, y)
# calcule x à la puissance y, donne un float
resultat = math.pow(2, 3) # 2 élevé à la puissance 3
print(resultat)
# 8.0
### Fonctions logarithmiques
## math.log(x)
# natural logarithm of x
print(math.log(1))
# 0.0
print(math.log(math.e))
# 1.0
print(math.log(10))
# 2.302585092994046
## math.log(x, b)
# logarithm of x to base b
print(math.log(8, 2))
# 3.0 (log₂(8) = 3 car 2³ = 8)
print(math.log(100, 10))
# 2.0 (log₁₀(100) = 2)
print(math.log(27, 3))
# 3.0 (log₃(27) = 3)
## math.log10(x)
# decimal logarithm of x (more precise than math.log(x, 10))
print(math.log10(10))
# 1.0
print(math.log10(100))
# 2.0
print(math.log10(1000))
# 3.0
## log2(x)
# binary logarithm of x (more precise than math.log(x, 2))
print(math.log2(2))
# 1.0
print(math.log2(8))
# 3.0
print(math.log2(16))
# 4.0
### Fonctions d'arrondi
## math.ceil(x)
# ceiling of x, plus petit entier ≥ x
print(math.ceil(4.1))
# 5
print(math.ceil(4.9))
# 5
print(math.ceil(-4.1))
# -4
print(math.ceil(4.0))
# 4
## math.floor(x)
# floor of x, plus grand entier ≤ x
print(math.floor(4.1))
# 4
print(math.floor(4.9))
# 4
print(math.floor(-4.1))
# -5
print(math.floor(4.0))
# 4
## math.trunc(x)
# value of x truncated to an integer
# not an equivalent of either ceil or floor
# troncature (supprime la partie décimale)
print(math.trunc(4.9))
# 4
print(math.trunc(-4.9))
# -4
print(math.trunc(4.0))
# 4
## math.fabs(x)
# calcule la valeur absolue d’un nombre
# Retourne toujours un float positif
# Utile pour obtenir la distance sans signe
print(math.fabs(-5))
# 5.0
print(math.fabs(3.14))
# 3.14
print(math.fabs(0))
# 0.0
def get_absolute_integer(num):
import math
return math.floor(math.fabs(num))
print(get_absolute_integer(-23.42))
# 23
### Factorielle
## math.factorial(x)
# returns x!
# x MUST be an INTEGER and POSITIVE
print(math.factorial(0))
# 1
print(math.factorial(1))
# 1
print(math.factorial(3))
# 6 (3! = 3×2×1)
print(math.factorial(5))
# 120 (5! = 5×4×3×2×1)
print(math.factorial(10))
# 3628800
# dans un code
print(math.factorial( -3.0 ))
# TypeError: 'float' object cannot be interpreted as an integer
# Python voit le - avent de voir le .,
print(math.factorial( 3.0 ))
# TypeError: 'float' object cannot be interpreted as an integer
print(math.factorial( -3))
# ValueError: factorial() not defined for negative values
### Hypoténuse
## math.hypot(x, y)
# returns the length of the hypotenuse of a right-angle triangle with the leg lengths equal to x and y
# the same as math.sqrt(pow(x, 2) + pow(y, 2)) but more precise
print(math.hypot(3, 4))
# 5.0 (triangle 3-4-5)
print(math.hypot(1, 1))
# 1.4142135623730951 (√2)
print(math.hypot(5, 12))
# 13.0 (triangle 5-12-13)
# si on ne met qu'un seul argument, int ou float, le return sera la meme valeur en float
print(math.hypot(4.0))
# 4.0
print(math.hypot(4))
# 4.0