« Mathématiques avec Python et Ruby/Nombres complexes en Python » : différence entre les versions

Contenu supprimé Contenu ajouté
Aucun résumé des modifications
mAucun résumé des modifications
Ligne 8 :
=Instanciation d'un nombre complexe=
 
Pour utiliser les nombres complexes dansDans ''Python'', le mieux est de charger le module ''cmath'' au début du script. Après ça, il suffit d'écrire ''complex(x,y)'' pour avoir un nombre complexe:
 
<source lang="python">
from cmath import *
z=complex(4,3)
print(z)
Ligne 21 ⟶ 20 :
 
<source lang="python">
from cmath import *
i=complex(0,1)
print(i**2)
Ligne 32 ⟶ 30 :
 
<source lang="python">
from cmath import *
a=complex(2,3)
b=complex(4,3)
Ligne 44 ⟶ 41 :
 
<source lang="python">
from cmath import *
i=complex(0,1)
print(i**i)
Ligne 54 ⟶ 50 :
 
<source lang="python">
from cmath import *
c=complex(7,24)
print(c**0.5)
Ligne 64 ⟶ 59 :
 
<source lang="python">
from cmath import *
print((-1)**0.5)
</source>
Ligne 75 ⟶ 69 :
 
<source lang="python">
from cmath import *
z=complex(4,3)
print(z.real)
Ligne 84 ⟶ 77 :
 
<source lang="python">
from cmath import *
z=complex(4,3)
print(z.conjugate())