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

Contenu supprimé Contenu ajouté
m →‎Octonions : oubli d'un point final
Ligne 369 :
 
Comme la multiplication des octonions n'est pas associative, les puissances des octonions ne présentent guère d'intérêt, sauf pour la puissance 2, et sur <math>\mathbb{O}</math>, l'ensemble des solutions de l'équation <math>z^2=-1</math> est une [[w:Hypersphère|sphère de dimension 7]].
 
 
==Résumé==
 
La classe ''Octonion'' de Python peut se résumer à ceci:
 
<source lang="python">
class Octonion:
def __init__(self,a,b):
self.a=a
self.b=b
 
def __str__(self):
aff='('
aff+=str(self.a.a.real)+')+('
aff+=str(self.a.a.imag)+')i+('
aff+=str(self.a.b.real)+')j+('
aff+=str(self.a.b.imag)+')k+('
aff+=str(self.b.a.real)+')l+('
aff+=str(self.b.a.imag)+')li+('
aff+=str(self.b.b.real)+')lj+('
aff+=str(self.b.b.imag)+')lk'
return aff
def __neg__(self):
return Octonion(-self.a,-self.b)
def __add__(self,other):
return Octonion(self.a+other.a,self.b+other.b)
def __sub__(self,other):
return Octonion(self.a-other.a,self.b-other.b)
def __mul__(self,other):
c=self.a*other.a-other.b*self.b.conjugate()
d=self.a.conjugate()*other.b+other.a*self.b
return Octonion(c,d)
def __rmul__(self,k):
return Octonion(k*self.a,k*self.b)
def __abs__(self):
return hypot(abs(self.a),abs(self.b))
def conjugate(self):
return Octonion(self.a.conjugate(),-self.b)
def __div__(self,other):
return self.conjugate()*(1./abs(other)**2*other)
</source>
 
Pour peu qu'on l'ait enregistrée dans un fichier ''octonions.py'', il suffit pour pouvoir effectuer des calculs sur les octonions, d'importer ce fichier par
 
<source lang="python">
from octonions import *
</source>
 
=Bibliographie=