-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcomplexes_II_2.py
More file actions
73 lines (56 loc) · 1.44 KB
/
complexes_II_2.py
File metadata and controls
73 lines (56 loc) · 1.44 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
##############################
# Complexes II
##############################
##############################
# Activité 2 - Passage polaire/cartésien
##############################
from math import *
import cmath
##############################
## Question 1 ##
def polaire_vers_cartesien(module,argument):
""" Passage de (r,theta) -> z = a+ib """
x = module*cos(argument)
y = module*sin(argument)
z = x + 1j*y
return z
# Test
print("--- Polaire vers cartésien ---")
z1 = polaire_vers_cartesien(3,pi/6)
z2 = cmath.rect(3,pi/6)
print(z1)
print(z2)
##############################
## Question 2 ##
def cartesien_vers_polaire(z):
""" Passage de z = a+ib -> (r, theta) """
x = z.real
y = z.imag
print(x)
print(y)
module = sqrt(x**2 + y**2)
argument = atan2(y,x)
return (module,argument)
# Test
print("--- Cartésien vers polaire ---")
mod_arg_1 = cartesien_vers_polaire(-2+5j)
mod_arg_2 = cmath.polar(-2+5j)
print(mod_arg_1)
print(mod_arg_2)
##############################
## Question 3 ##
def argument_dans_intervalle(angle):
""" Ramène un angle dans l'intervalle ]-pi,+pi]
par réduction modulo 2pi """
k = floor(angle/(2*pi))
print(k)
new_angle = angle - 2*k*pi
if new_angle > pi:
new_angle += -2*pi
return new_angle
# Test
print("--- Argument dans intervalle ---")
theta = -pi/2 + 12*pi
print(theta)
print(argument_dans_intervalle(theta))
print(theta % 2*pi)