"'O
0
c
:J
0
:<:;
li)
.,,
..--t
c::
:l
0
~
N
"
@
~
.......
0
J::
:;
O'l
"'
·;::::
c::
0
>c::
o.
c::
0
.9
u
ü
:l
.,,
2
o.
~
"
:;
0
11
.,,
0
c:
:l
0
QJ
10.5 · Calcul matriciel
listecoefs - []
#initialisation des coefficients : liste vide
matA - [[0,0,0],[0,0,0],[0,0,0]] # initialisation de la matrice A
Pour p de 0 à N Faire
Afficher "x_",p,"="
Saisir coef
#Saisie des coefficients x_O, ... , x_n
Ajouter coef à listecoefs
Fin Pour
Pour p de 0 à 2 Faire
Pour q de 0 à 2 Faire
1
Afficher "a_",p+ l ,",",q+ l ,"="
Saisir matA[p][q]
#Saisie des éléments de A
Fin Pour
Fin Pour
s - [[0,0,0],[0,0,0],[0,0,0]]
Pour p de 0 à N Faire
1
S - so(S,produitR(listecoefs[p],puissance(A,p)))
Fin Pour
Afficher "Matrice obtenue :"
Afficher(S[O])
#première ligne de la matrice x_0"'1_3+ ... +x_n '"A
Afficher(S[l])
#deuxième ligne de la matrice x_0"' 1_3+ ... +x_n"'A
Afficher(S[2])
# troisième ligne de la matrice x_0 "'1_3+ ... +x_n"'A
Fin
b) Implémentation Python
#########################Fonction s #############################
def s o ( A,B) :
C= [ [ 0 , 0 , O], [ 0 , 0 , O] , [ 0 , 0 , O]]
for 1 1n ran ge( 0 ,3 ) :
for j in range(0 ,3) :
C[ i ] [ j ] =A[ i ] [ j ] + B[ i ] [ j ]
return(C)
def produit R( x, A):
C=[ [ 0 , 0 , 0] ' [ 0 , 0 , 0] ' [ 0 , 0 , 0]]
for i 1n ran ge( 0 ,3):
for j in r ange(0,3):
C[ i ] [ j ] =X * A[ i ] [ j ]
return(C)
def produit (A, B):
C= [ [ 0 , 0 , O], [ 0 , 0 , O] , [ 0 , 0 , O]]
for i in ran ge(0,3):
for j in r a n ge( 0 , 3):
for k in ran ge( 0 ,3) :
C[ i ] [ j ] =C[ i ] [ j ] +A[ i ] [ k] * B[ k] [ j ]
r e turn (C)
def pui ssa nce(A,n) :
if n==O:
r et ur n ( [ [ 1, 0 , 0] , [ 0 , 1, 0] , [ 0 , 0 , 1]] )
e l se :
r et urn(produi t(pui ssa n ce(A, n - 1) , A))
237
Précédent

- 245/302

Suivant