• Aucun résultat trouvé

Algèbre linéaire avec Maple 1. Le package linalg. 2. Création d’une matrice. 3. Equivalence matricielle. 4. Similitude matricielle. 5. Espaces euclidiens.

N/A
N/A
Protected

Academic year: 2022

Partager "Algèbre linéaire avec Maple 1. Le package linalg. 2. Création d’une matrice. 3. Equivalence matricielle. 4. Similitude matricielle. 5. Espaces euclidiens."

Copied!
23
0
0

Texte intégral

(1)

Algèbre linéaire avec Maple

1. Le package linalg.

2. Création d’une matrice.

3. Equivalence matricielle.

4. Similitude matricielle.

5. Espaces euclidiens.

Pierre-Jean Hormière __________

1. Le package linalg.

> with(linalg);

BlockDiagonal GramSchmidt JordanBlock LUdecomp QRdecomp Wronskian , , , , , , [

addcol addrow adj adjoint angle augment backsub band basis bezout , , , , , , , , , , blockmatrix charmat charpoly cholesky col coldim colspace colspan , , , , , , , ,

companion concat cond copyinto crossprod curl definite delcols delrows det , , , , , , , , , , diag diverge dotprod eigenvals eigenvalues eigenvectors eigenvects entermatrix , , , , , , , , equal exponential extend ffgausselim fibonacci forwardsub frobenius gausselim , , , , , , , , gaussjord geneqns genmatrix grad hadamard hermite hessian hilbert , , , , , , , ,

htranspose ihermite indexfunc innerprod intbasis inverse ismith issimilar iszero , , , , , , , , , jacobian jordan kernel laplacian leastsqrs linsolve matadd matrix minor , , , , , , , , , minpoly mulcol mulrow multiply norm normalize nullspace orthog permanent , , , , , , , , , pivot potential randmatrix randvector rank ratform row rowdim rowspace , , , , , , , , , rowspan rref scalarmul singularvals smith stackmatrix submatrix subvector , , , , , , , , sumbasis swapcol swaprow sylvester toeplitz trace transpose vandermonde , , , , , , , , vecpotent vectdim vector wronskian , , , ]

Ce package contient divers programmes :

création d’une matrice : array, matrix, vector, concat, augment, stackmatrix, diag, blockmatrix, BlockDiagonal, hilbert, etc.

calculs, manipulations et tests divers : coldim, rowdim, addcol, addrow, mulcol, mulrow, matadd, scalarmul, swapcol, swaprow, multiply, inverse, transpose, htranspose, pivot, submatrix, minor, trace, det, permanent, iszero, equal, etc.

équivalence matricielle : opérations élémentaires, rang, image, noyau, résolution de systèmes linéaires à coefficients dans des corps Q, R, C, ou des corps formels Q(a, b, c, d), etc. : rank, colspan, colspace, rowspan, rowspace, kernel, nullspace, gaussjord, rref, linsolve, LUdecomp, etc.

résolution de systèmes à coeffs dans Z ou Q[X] : ismith, ihermite, isolve, smith, hermite, etc.

• similitude matricielle : eigenvals, eigenvects, charpoly, minpoly, jordan, frobenius, issimilar, etc.

euclidiens ou hermitiens : norm, cond, dotprod, crossprod, orthog, GramSchmidt, QRdecomp, singularvals, leastsqrs, hadamard, etc.

Tous ces programmes ne sont pas à connaître par cœur. Pour chacun d’eux, on peut demander :

une aide en ligne, qui indique comment cela marche, et donne des exemples : Exemple : > ?charpoly ;

l’algorithme même. Exemple : > interface(verboseproc = 2) ; eval(gaussjord) ;

Maple contient aussi un package LinearAlgebra dont je ne sais à peu près rien…

(2)

2. Création d’une matrice.

> with(linalg):

> v:=vector([1,3,7]);v:=vector(3,[1,3,7]);v:=array(1..3,[1,3,7]);

:=

v [ 1 3 7 , , ] :=

v [ 1 3 7 , , ] :=

v [ 1 3 7 , , ]

>

A:=array(1..2,1..4,[[1,2,3,4],[4,3,2,1]]);A:=matrix(2,4,[[1,2,3,4],[4,3,2, 1]]);A:=matrix(2,4,[1,2,3,4,4,3,2,1]);

>

A:=matrix(4,4,(i,j)->min(i,j));A:=matrix(4,4,proc(i,j) min(i,j) end);

:=

A

 

 

 



 

 

 



1 1 1 1

1 2 2 2

1 2 3 3

1 2 3 4

> A:=array(1..3,1..3,antisymmetric):A[3,2]:=p:A[1,3]:=q:A[2,1]:=r:print(A);

 

 

 

 

0 −r q

r 0 −p

−q p 0

> coeffA:=rand(-10..10):n:=5:A:=matrix(n,n,[seq(coeffA(),i=1..n^2)]);

:=

A

 

 

 

 



 

 

 

 



-4 7 8 10 -6

-8 -5 7 6 -6

0 5 -10 1 1

-3 -10 5 -4 -8

-1 -10 2 3 -1

> A:=matrix(3,3,[3,6,1,0,0,4,-1,-2,-

3]):J:=diag(1,1,1):Z:=matrix(3,3,0):M:=blockmatrix(2,2,[A,J,Z,A]);

:=

M

























3 6 1 1 0 0

0 0 4 0 1 0

-1 -2 -3 0 0 1

0 0 0 3 6 1

0 0 0 0 0 4

0 0 0 -1 -2 -3

> A:=matrix(2,2,[x^2+1,x^3+2*x+8,x^5-8*x^4+x-7,3*x^2+4*x- 56]);B:=map(diff,A,x);C:=map(exp,B);

:=

A

 

 

+

x

2

1 x

3

+ + 2 x 8 − + −

x

5

8 x

4

x 7 3 x

2

+ − 4 x 56

> A:=matrix(2,2,[x*sin(1/x),cos(1/x),cos(1/x),x*tan(1/x)]);

:=

A

 

 

 

 

 

 

x

  

 

sin 1 x

  

 

cos 1 x

  

 

cos 1

x x

  

 

tan 1 x

> map(limit,A,x=infinity);map(asympt,A,x,4);

:=

A

  

 

1 2 3 4

4 3 2 1 A := 

  

 

1 2 3 4

4 3 2 1 A := 

  

 

1 2 3 4

4 3 2 1

:=

A

 

 

 



 

 

 



1 1 1 1

1 2 2 2

1 2 3 3

1 2 3 4

:=

B





2 x 3 x2 + 2 − +

5 x4 32 x3 1 6 x + 4 C :=









eee

e(2 x) eeee(3 x + )

2 2

e ee

e(5 x + )

4 32 x3 1

e ee e(6 x + 4)

(3)

  

 

1 1

1 1

 

 

 

 



 

 

 

 



− + 1 1

6 1 x

2

  

 

O 1

x

4

1 − 1 + 2

1 x

2

  

 

O 1 x

4

− + 1 1

2 1 x

2

  

 

O 1

x

4

1 + + 1 3 x

2

  

 

O 1 x

4

Exercice : Explorer et étudier les matrices de Fibonacci du package linalg.

Créations de matrices aléatoires :

> randmatrix(3,3);randmatrix(3,3,symmetric);randmatrix(3,3,antisymmetric);

randmatrix(3,3,unimodular);randmatrix(3,3,entries=rand(-6..6));

>

with(LinearAlgebra):

RandomVector(2);

  

 

-71 28

> RandomVector[row](6,generator=rand(1..5)/10);

  

 

, , , , , 1

5 1 10

3 10

2 5

1 5

2 5

> RandomMatrix(3,density=0.75,generator=0..0.5);

 

 

 

 

0. .329495602458761638 .0730103250672744508 0. .363489042803815110 .370278606642740371 .370840792758260207 .122401385169373711 .137768350871747102

> RandomMatrix(4,4,generator=1..9,outputoptions=[shape=triangular[lower]]);

 

 

 



 

 

 



1 0 0 0

6 1 0 0

3 1 7 0

4 2 3 9

On peut aussi utiliser le package RandomTools.

> with(RandomTools);

[ AddFlavor Generate GetFlavor GetFlavors HasFlavor RemoveFlavor , , , , , ]

> Matrix(3,3,Generate(choose({0,1}),makeproc=true));

 

 

 

 

1 0 1

1 0 0

1 0 1

> Matrix(3,3,Generate(rational(denominator=10),makeproc));

























0 3

10 -2

5 -1

2 -1

5 -1 10 -9

10 1 2

4 5

> Vector(4,Generate(complex(integer(range=1..100)),makeproc));

 

 

 

 

-63 -90 61 -3 -82 16 -40 21 -94

 

 

 

 

-98 75 95

75 39 -68 95 -68 98

 

 

 

 

0 -36 -95

36 0 8

95 -8 0

 

 

 

 

1 92 8

0 1 -95

0 0 1

 

 

 

 

4 -2 5

-4 -2 -4

3 -1 0

(4)

 

 

 



 

 

 



+ 8 50 I

+ 87 99 I

+ 67 10 I

+ 74 82 I Matrice d’un système linéaire :

eqns := {2*x+y+z=a,x+2*y+z=b,x+y+2*z=c};

A:=genmatrix(eqns,[x,y,z]);B:=genmatrix(eqns,[x,y,z,a,b,c]);

:=

eqns { 2 x + + y z = a , x + + 2 y z = b , x + + y 2 z = c }

Inverse et conditionnement d’une matrice :

> hilbert(3);inverse(hilbert(3));cond(hilbert(3));

Le conditionnement d’une matrice mesure la sensibilité de cette matrice vis à vis des conditions initiales. Une matrice inversible est mal conditionnée (i.e. a un grand nombre de conditionnement) si une légère perturbation du second membre du système Ax = b conduit à de grandes variations du vecteur inconnu x. Les matrices de Hilbert sont mal conditionnées.

Calcul d’un déterminant :

> A:=vandermonde([a,b,c,d,z]):

> B:=delcols(delrows(A,5..5),3..3);factor(det(B));

:=

B

 

 

 

 

 

 

 

 

1 a a

3

a

4

1 b b

3

b

4

1 c c

3

c

4

1 d d

3

d

4

( − + d c ( ) bd ( ) bc ( ) − + d a ( ) ac ( ) ab ( ) c a + + + + + d a a b d c b c b d ) Ci-dessous est vérifié le lien entre matrice de Vandermonde et matrice de Lagrange :

> A:=vandermonde([a,b,c]);B:=inverse(A);

:=

A

 

 



 

 



1 a a

2

1 b b

2

1 c c

2

:=

B

 

 

 

 

 

 

 

 

 

 

 

 

c b

− + −

c b a b a

2

a ca c

− + − + a c a b b

2

c b

a b

− + + − a c a b c

2

c b

b + c − + − c b a b a

2

a c

+ a c

− + − + a c a b b

2

c ba + b

− + + − a c a b c

2

c b 1

− + −

c b a b a

2

a c − 1

− + − + a c a b b

2

c b

1

− + + − a c a b c

2

c b

> p:=interp([a,b,c],[A,B,C],x);

> M:=map(simplify,genmatrix([coeff(p,x,0)=0,coeff(p,x,1)=0,coeff(p,x,2)=0], [A,B,C]));

:=

A

 

 

 

 

2 1 1

1 2 1

1 1 2

:=

B

 

 

 

 

2 1 1 -1 0 0

1 2 1 0 -1 0

1 1 2 0 0 -1

 

 

 

 

9 -36 30

-36 192 -180 30 -180 180

748

























1 1

2 1 3 1

2 1 3

1 4 1

3 1 4

1 5

(5)

:=

M

























c b

(− + c a () ab) − a c (ab () − + c b)

a b (− + c a () − + c b)

b + c (− + c a () ab)

+ a c

(ab () − + c b) − a + b (− + c b () − + c a) 1

(− + c a () ab) − 1 (ab () − + c b)

1

(− + c b () − + c a)

> iszero(map(simplify,evalm(M-B)));

true Exercice : Expliquer ce résultat.

Exercice : Calculer det( C

ii+j

)

0i,jn

.

Solution : Pour n = 3, Maple donne ceci, qui reste à justifier et à généraliser :

> with(linalg):

> A:=matrix(5,5,(i,j)->binomial(i+j-2,i-1));det(A);

Exercice : Calculer et factoriser

1 2 1

2 1 1

1 2 1

a a b b

a a c c

b b c c

+ +

+ +

+ +

(Polya-Szegö, t. 2, n° 9, p. 93).

> with(linalg):

> A:=matrix(3,3,[2,c+1/c,b+1/b,c+1/c,2,a+1/a,b+1/b,a+1/a,2]);

:=

A

























2 c + 1

c b + 1 b +

c 1

c 2 a + 1 a +

b 1 b a + 1

a 2

> factor(det(A));

−2 ( ac b ( ) b ac ( ) c b a − 1 ( ) c ab ) a

2

c

2

b

2

3. Equivalence matricielle, systèmes linéaires.

Sont ici regroupées quelques procédures relatives aux vecteurs, aux sous-espaces qu’ils engendrent, aux bases, aux matrices rectangulaires et aux systèmes linéaires généraux.

Commençons par vérifier la formule de Grassmann sur un exemple :

> a:=vector([1,2,3,4]);b:=vector([2,2,2,6]);c:=vector([0,2,4,4]);

d:=vector([1,0,-1,2]);f:=vector([2,3,0,1]);

>

basis({a,b,c});basis({d,f});intbasis({a,b,c},{d,f});

basis({a,b,c,d,f});sumbasis({a,b,c},{d,f});

:=

A

 

 

 

 



 

 

 

 



1 1 1 1 1

1 2 3 4 5

1 3 6 10 15

1 4 10 20 35

1 5 15 35 70

1

:=

a [ 1 2 3 4 , , , ] b := [ 2 2 2 6 , , , ] c := [ 0 2 4 4 , , , ] :=

d [ 1 0 -1 2 , , , ] f := [ 2 3 0 1 , , , ]

(6)

{ a b c , , } { f d , } { [ -1 0 1 -2 , , , ] }

> A:=transpose(matrix([a,b,c,d,f]));rank(A);gaussjord(A);

Voici une procédure prenant en argument une matrice et affichant ses principales caractéristiques.

On notera que certains programmes sont synonymes.

> matrice:=proc(A)

> local n,p,r,x,y,z,t,R,S,T;

> n:=rowdim(A);p:=coldim(A);r:=rank(A);

> x:=array(1..p);y:=array(1..n);z:=array(1..r);t:=array(1..p-r);

> print("format : ",n,p);

> print("rang : ",r);

> print("base de l'image : ",colspace(A));

> print("base de l'image :",colspan(A));

> R:=matrix([op(colspan(A))]);S:=matrix([op(kernel(A))]);

T:=matrix([op(kernel(transpose(A)))]);

> print("équations paramétriques de l'image :",multiply(A,x));

> print("équations paramétriques de l'image :",multiply(transpose(R),z));

> print("équations cartésiennes de l'image :",geneqns(T,y));

> print("base des lignes :",rowspace(A));

print("base des lignes :",rowspan(A));

> print("base du noyau :",kernel(A));print("base du noyau :",nullspace(A));

> print("équations cartésiennes du noyau :",geneqns(A,x));

> print("équations cartésiennes du noyau :",geneqns(S,x));

> print("équations paramétriques du noyau :",multiply(transpose(S),t));

> print("réduite échelonnée en lignes :",rref(A));

> print("réduite échelonnée en lignes :",gaussjord(A));

> print("réduite échelonnée en colonnes :",transpose(rref(transpose(A))));

> print("réduite unicorde :",transpose(rref(transpose(rref(A)))));

> end;

> A:=matrix(3,4,[0,1,2,3,1,2,3,4,2,3,4,5]);matrice(A);

:=

A

 

 

 

 

0 1 2 3

1 2 3 4

2 3 4 5

, ,

"format : " 3 4 ,

"rang : " 2 ,

"base de l'image : " { [ 0 1 2 , , ] , [ 1 0 -1 , , ] } ,

"base de l'image :" { [ 0 1 2 , , ] , [ 1 2 3 , , ] }

"équations paramétriques de l'image :" ,

[ x

2

+ 2 x

3

+ 3 x

4

, x

1

+ 2 x

2

+ 3 x

3

+ 4 x

4

, 2 x

1

+ 3 x

2

+ 4 x

3

+ 5 x

4

] ,

"équations paramétriques de l'image :"[ z , , ]

1

2 z +

1

z

2

3 z +

1

2 z

2

,

"équations cartésiennes de l'image :"{ y

1

2 y

2

+ y

3

= 0 } ,

"base des lignes :" { [ 1 0 -1 -2 [ , , , ] , 0 1 2 3 , , , ] } ,

"base des lignes :" { [ 0 1 2 3 , , , ] , [ 1 2 3 4 , , , ] }

















1 0 0 -1 0

0 1 0 1 0

0 0 1 0 0

0 0 0 0 1

{ a f d c , , , } { a f b c , , , }

:= 4 A

 

 

 



 

 

 



1 2 0 1 2

2 2 2 0 3

3 2 4 -1 0

4 6 4 2 1

(7)

,

"base du noyau :" { [ 1 -2 1 0 , , , ] , [ 2 -3 0 1 , , , ] } ,

"base du noyau :" { [ 1 -2 1 0 , , , ] , [ 2 -3 0 1 , , , ] }

"équations cartésiennes du noyau :" ,

{ x

2

+ 2 x

3

+ 3 x

4

= 0 , x

1

+ 2 x

2

+ 3 x

3

+ 4 x

4

= 0 , 2 x

1

+ 3 x

2

+ 4 x

3

+ 5 x

4

= 0 } ,

"équations cartésiennes du noyau :"{ x

2

2 x

3

+ x

4

= 0 , x

1

2 x

2

+ x

3

= 0 } ,

"équations paramétriques du noyau :"[ t

2

, t

1

2 t

2

, − 2 t

1

+ t

2

, t

1

]

,

"réduite échelonnée en lignes :"

 

 

 

 

1 0 -1 -2

0 1 2 3

0 0 0 0

,

"réduite échelonnée en lignes :"

 

 

 

 

1 0 -1 -2

0 1 2 3

0 0 0 0

,

"réduite échelonnée en colonnes :"

 

 

 

 

1 0 0 0

0 1 0 0

-1 2 0 0

,

"réduite unicorde :"

 

 

 

 

1 0 0 0

0 1 0 0

0 0 0 0

L’inconvénient des procédures rref et gaussjord est qu’elles n’affichent pas les matrices de passage.

Si l’on veut les afficher, il faut programmer le pivot.

> with(linalg):

> echelon:=proc(A)

> local M,n,p,i,j,line;

> M:=A;

> n:=rowdim(A);p:=coldim(A);line:=1;

> for j from 1 to p do

> for i from line to n while M[i,j]=0 do od;

> if i <=n then

> M:=swaprow(M,i,line);

> M:=mulrow(M,line,1/M[line,j]);

> M:=pivot(M,line,j);

> line:=line+1;fi;

> od;eval(M);end;

> echelonligne:=proc(A)

> local n,p,J,M,R;

> n:=rowdim(A);p:=coldim(A);

> J:=array(1..n,1..n,identity);M:=augment(A,J);

> R:=echelon(M);

> print("réduite échelonnée en ligne : RL = ", submatrix(R,1..n,1..p));

> print("matrice inversible Q telle que QA = RL :

",submatrix(R,1..n,p+1..p+n));

> end;

> echeloncolonne:=proc(A)

> local n,p,B,J,M,R;

> B:=transpose(A);p:=rowdim(B);n:=coldim(B);

> J:=array(1..p,1..p,identity);M:=augment(B,J);

> R:=echelon(M);

> print("réduite échelonnée en colonne : RC = ", transpose(submatrix(R,1..p,1..n)));

(8)

> print("matrice inversible P telle que AP = RC :

",transpose(submatrix(R,1..p,n+1..p+n)));

> end;

> unicorde:=proc(A)

> local n,p,J,K,M,R,RL,Q,TRL,N,P,S,RU;

> n:=rowdim(A);p:=coldim(A);

> J:=array(1..n,1..n,identity);K:=array(1..p,1..p,identity);

> M:=augment(A,J);R:=echelon(M);

> RL:=submatrix(R,1..n,1..p);

> Q:=submatrix(R,1..n,p+1..p+n);

> TRL:=transpose(RL);N:=augment(TRL,K);

> S:=echelon(N);

> RU:=transpose(submatrix(S,1..p,1..n));

> P:=transpose(submatrix(S,1..p,n+1..n+p));

> print("réduite unicorde : ",RU);

> print("matrices inversibles Q et P telles que QAP = RU :",Q,P);

> end;

> A:=matrix(3,4,[0,1,2,3,1,2,3,4,2,3,4,5]);

:=

A

 

 

 

 

0 1 2 3

1 2 3 4

2 3 4 5

> echelonligne(A);echeloncolonne(A);unicorde(A);

,

"réduite échelonnée en ligne : RL = "

 

 

 

 

1 0 -1 -2

0 1 2 3

0 0 0 0

,

"matrice inversible Q telle que QA = RL : "

 

 

 

 

0 -3 2 0 2 -1 1 -2 1

,

"réduite échelonnée en colonne : RC = "

 

 

 

 

1 0 0 0

0 1 0 0

-1 2 0 0

,

"matrice inversible P telle que AP = RC : "

 

 

 



 

 

 



0 0 1 0

0 0 0 1

-4 3 -3 -2

3 -2 2 1

,

"réduite unicorde : "

 

 

 

 

1 0 0 0

0 1 0 0

0 0 0 0

, ,

"matrices inversibles Q et P telles que QAP = RU :"

 

 

 

 

0 -3 2 0 2 -1 1 -2 1

 

 

 



 

 

 



0 0 1 0

0 0 0 1

3 2 -3 -2

-2 -1 2 1

Exercice 1 : Explorer les procédures gaussjord et LUdecomp.

Exercice 2 : Résoudre les équations : A.X = B , où A =

− −

1 0 1

1 1 3

0 1 2

et B =

− −

− 0 1 1

3 0 2

3 1 1

; X.A = B, où A =

 − 0 0 0

1 1 2

1 1 3

et B =

− −

− −

− 1 2 1

1 2 1

1 2 1

.

(9)

> A:=matrix(3,3,[2,1,0,-3,-1,1,1,0,-1]);B:=matrix(3,3,[1,1,3,-2,0,-3,1,- 1,0]);linsolve(A,B);

:=

A

 

 

 

 

2 1 0

-3 -1 1 1 0 -1

 

 

 

 



 

 

 

 



+ 1 _t

11

− + 1 _t

21

_t

3 1

− − 1 2 _t

1

1

− 3 2 _t

2

1

− 3 2 _t

3

1

_t

1

1

_t

2

1

_t

3

1

> A:=matrix(3,3,[3,1,1,2,-1,1,0,0,0]);B:=matrix(3,3,[1,-2,-1,1,-2,-1,1,-2,- 1]);linsolve(transpose(A),transpose(B));

Le second système n’a pas de solution.

Exercice 3 : Résoudre le système de congruences :

x + 2y + 3z ≡ 1 (mod 5)

x + 3y ≡ 2 (mod 5)

x + 4y + 3z

3 (mod 5)

Solution : La commande Linsolve permet de résoudre des systèmes linéaires modulo n.

> A := matrix([[1,2,3],[1,3,0],[1,4,3]]);

:=

A

 

 

 

 

1 2 3

1 3 0

1 4 3

> b := vector([1,2,3]);

:=

b [ 1 2 3 , , ]

> x := Linsolve(A,b) mod 5;

:=

x [ 4 1 0 , , ] Exercice 4 : Résoudre et discuter le système

3m x + (3m − 7) y + (m − 5) z = m − 1

(2m − 1) x + (4m − 1) y + 2m z = m + 1

4m x + (5m – 7) y + (2m – 5) z = 0 Solution :

Maple fait très bien cela, mais attention ! il y a un problème, sur lequel on reviendra au § 4.5. En effet, Maple affirme que la matrice du système est inversible. Or il en bien ainsi… dans M

3

(Q(m)), où Q(m) est le corps des fractions rationnelles à une indéterminée m, car le déterminant du système est –m(m + 2), qui est non nul en tant qu’élément de Q(m). Si l’on se place dans Q, il faut discuter selon que les valeurs de m, et l’on s’aperçoit que pour m = 0 ou

2 le système est impossible.

> with(linalg):

> A:=matrix(3,3,[3*m,3*m-7,m-5,2*m-1,4*m-1,2*m,4*m,5*m-7,2*m- 5]);b:=array([m-1,m+1,0]);

> rank(A);inverse(A);linsolve(A,b);Delta:=factor(det(A));

3

:=

A









3 1 1

2 -1 1

0 0 0

:=

B

 

 

 

 

1 -2 -1 1 -2 -1 1 -2 -1 :=

B

 

 

 

 

1 1 3

-2 0 -3 1 -1 0

:=

A

 

 

 

 

3 m 3 m − 7 m − 5 −

2 m 1 4 m − 1 2 m 4 m 5 m − 7 2 m − 5 :=

b [ m − 1 , m + 1 0 , ]

(10)

 

 

 

 

 

 

 

 

 

 

 

 

 + −

2 m

2

8 m 5 m ( m + 2 )

+ m 3

+

m 2 − 2 m

2

+ 7 m − 5 m ( m + 2 )

4 m

2

+ 12 m − 5

m ( m + 2 ) − 2 m + 5 + m 2

+ − 4 m

2

11 m 5

m ( m + 2 ) + −

15 m 6 m

2

7 m ( m + 2 )

+ 7 3 m

+

m 2 − 6 m

2

+ 14 m − 7 m ( m + 2 )

  

 

, ,

− + +

10 m

2

10 m 3 m

3

5

m ( m + 2 ) − 15 m

2

12 m + 6 m

3

+ 5 m ( m + 2 )

+ − +

9 m

3

19 m

2

15 m 7 m ( m + 2 )

∆ := −m ( m + 2 )

> A0:=subs(m=0,op(A));b0:=subs(m=0,op(b));linsolve(A0,b0);

rank(A0);colspace(A0);

> A1:=subs(m=-2,op(A));b1:=subs(m=-2,op(b));linsolve(A1,b1);

rank(A1);colspace(A1);

4. Similitude matricielle.

Sont ici groupées les procédures spécifiques aux matrices carrées : déterminant, trace, polynômes caractéristique et minimal, valeurs et vecteurs propres, sous-espaces propres et caractéristiques, diagonalisation et trigonalisation, sous-espaces stables, puissances et exponentielles de matrices, commutants et racines carrées, etc.

4.1. Le problème du chamelier.

Exercice : Un chamelier circule entre les trois oasis A, B et C. Il peut aller en une étape de A à B, de C à B et de B à C, et enfin de C à A. Chercher le nombre d’itinéraires en 100 étapes de C à A.

> with(linalg):

> A:=matrix(3,3,[0,1,0,0,0,1,1,1,0]);

:=

A

 

 

 

 

0 1 0

0 0 1

1 1 0

> evalm(A^100);%[3,1];

 

 

 

 

288627200960 506505428836 382349636061 382349636061 670976837021 506505428836 506505428836 888855064897 670976837021

506505428836

> M:=minpoly(A,x);

:=

M − − + 1 x x

3

> R:=rem(x^100,M,x);evalm(subs(x=A,R));

:=

R 382349636061x

2

+ 506505428836x + 288627200960

 

 

 

 

288627200960 506505428836 382349636061 382349636061 670976837021 506505428836 506505428836 888855064897 670976837021 :=

A0

 

 

 

 

0 -7 -5 -1 -1 0 0 -7 -5

:=

b0 [ -1 1 0 , , ] 2 { [ 0 1 0 , , ] , [ 1 0 1 , , ] }

:=

A1

 

 

 

 

-6 -13 -7 -5 -9 -4 -8 -17 -9

:=

b1 [ -3 -1 0 , , ] 2 {  , }

  

 

, , 1 0 13

11

  

 

, , 0 1 2

11

(11)

4.2. Récurrences linéaires, puissances d’une matrice.

Etudions les suites récurrentes linéaires u

n+1

= u

n

+ 2 v

n

, v

n+1

= u

n

+ v

n

, u

0

= v

0

= 1.

Matriciellement, il s’agit de calculer la puissance n-ième de A =





 1 1

2

1 , ce qui peut se faire par diagonalisation de A.

> with(linalg):A:=matrix(2,2,[1,2,1,1]);c:=charpoly(A,x);

f:=factor(charpoly(A,x),sqrt(2));

:=

A

  

 

1 2

1 1

:=

c x

2

− − 2 x 1 :=

f −( x − + 1 2 ( ) − + + x 1 2 )

> alias(alpha=1-sqrt(2),beta=1+sqrt(2));

k1:=kernel(A-alpha);k2:=kernel(A-beta);

α β ,

> P:=transpose(matrix([op(k1),op(k2)]));

map(simplify,multiply(inverse(P),A,P));

:=

P

 

 

 

 

1 1

− 1

2 2 1

2 2

> An:=multiply(P,diag(alpha^n,beta^n),inverse(P));

:=

An

 

 

 

 

 

 

1 + 2 α

n

1

2 β

n

− 1 +

2 2 α

n

1 2 2 β

n

− 1 +

4 2 α

n

1

4 2 β

n

1 +

2 α

n

1 2 β

n

> V:=multiply(An,vector([1,1]));limit(V[1]/V[2],n=infinity);

:=

V

  

 

+ − + , 1

2 α

n

1 2 β

n

1

2 2 α

n

1

2 2 β

n

− 1 + + +

4 2 α

n

1

4 2 β

n

1 2 α

n

1

2 β

n

2 β

+

2 2

Mais on peut aussi recourir à la commande rsolve, qui fournit en outre les fonctions génératrices:

> rsolve({u(n+1)=u(n)+2*v(n),v(n+1)=u(n)+v(n),u(0)=1,v(0)=1},{u,v});

= ( ) u n 1

2

+ + −

 



1

− + 1 2

n

2

 



1

− + 1 2

n

 



− 1

+

1 2

n

2

 



− 1

+

1 2

n

(− + 1 2 () 1 + 2) ,







= ( )

v n 1

4 2

 

 

+ − +

  

 

1

− + 1 2

n

2 

  

 

1

− + 1 2

n

  

 

− 1

+

1 2

n

2 

  

 

− 1

+

1 2

n

( − + 1 2 ( ) 1 + 2 )

 

 

 

>

rsolve({u(n+1)=u(n)+2*v(n),v(n+1)=u(n)+v(n),u(0)=1,v(0)=1},{u,v},'genfunc' (x));

{ v x ( ) = − 1 , }

− +

x

2

1 2 x u x ( ) = − x + 1 − + x

2

1 2 x

Etudions les suites récurrentes u

n+2

= u

n+1

+ u

n

, x

n+2

= x

n+1

+ x

n

+ u

n

, u

0

= x

0

= 0 , u

1

= x

1

= 1.

On reconnaît la suite de Fibonacci et une « Fibonacci itérée ».

:=

k2 {  }

  

 

, 1 1

2 2 :=

k1 {  }

  

 

, 1 − 1

2 2

  

 

α 0

0 β

(12)

La commande rsolve marche, mais on peut aussi procéder autrement, car si T est l’opérateur de décalage, alors u

Ker(T

2

– T – I) et x

Ker(T

2

– T – I)

2

.

> rsolve({u(n+2)=u(n+1)+u(n),u(0)=0,u(1)=1},u);

+

  

 

− + 1 1 5 5 

  

 

−2 1

1 5

n

1 5

  

 

− 1 −

5 5 1 

  

 

−2 1

+

1 5

n

+

1 5

> rsolve({u(n+2)=u(n+1)+u(n),u(0)=0,u(1)=1},u,'genfunc'(x));

x

− + + 1 x x

2

> rsolve({u(n+2)=u(n+1)+u(n),x(n+2)=x(n+1)+x(n)+u(n),u(0)=0,u(1)=1,x(0)=0, x(1)=1},{u,x});

= ( ) u n −4

5 5

 



 −

 



−2 1 +

1 5

n

 



2 1

− + 1 5

n

(− + 1 5 () 1 + 5) x n( ) 8 25 6

 



2 1

− + 1 5

n

− 5



− = ,







5 

  

 

2 1

− + 1 5

n

n 5 

  

 

2 1

− + 1 5

n

5 n 6 

  

 

− 2 1 +

1 5

n

+ − + 5

5

 



−2 1

+

1 5

n

5 n 5

 



−2 1

+

1 5

n

+ + n (− + 1 5)2(1 + 5)2

 ( )







> rsolve({u(n+2)=u(n+1)+u(n),x(n+2)=x(n+1)+x(n)+u(n),u(0)=0,u(1)=1,x(0)=0, x(1)=1},{u,x},'genfunc'(z));

{ x z ( ) = − z ( z − 1 ) , }

− − + +

1 2 z z

2

2 z

3

z

4

u z ( ) = − z

− + + 1 z z

2

Exercice : étudier les suites récurrentes u

n+5

= u

n+4

+ 5.u

n+3

– u

n+2

– 8.u

n+1

– 4.u

n

. Lesquelles sont bornées ? convergentes ?

Solution : via le théorème des noyaux, cela donne :

> P:=X^5-X^4-5*X^3+X^2+8*X+4;factor(P);

:=

P X

5

− − X

4

5 X

3

+ + X

2

8 X + 4 ( X − 2 )

2

( X + 1 )

3

> u:=n->(a*n+b)*2^n+(c*n^2+d*n+e)*(-1)^n;

:=

u n → ( a n + b 2 )

n

+ ( c n

2

+ + d n e ( ) -1 )

n

Les suites bornées correspondent à a = b = c = d = 0 ; elles sont du type e(−1)

n

. La seule suite convergente est la suite nulle.

> restart;rsolve({u(n+5)=u(n+4)+5*u(n+3)-u(n+2)-8*u(n+1)-4*u(n)},u);

  

 

− − − +

1

18 u 4 ( ) 7

18 u 1 ( ) 4

27 u 0 ( ) 5

18 u 2 ( ) 1

54 u 3 ( ) 2

n

  

 

− − − +

1

54 u 4 ( ) 5

54 u 1 ( ) 1

27 u 0 ( ) 1

18 u 2 ( ) 1

54 u 3 ( ) ( n + 1 2 )

n

+

  

 

+ + − −

2

9 u 4 ( ) 4

9 u 1 ( ) 56

27 u 0 ( ) 10

9 u 2 ( ) 7

27 u 3 ( ) ( -1 )

n

+

  

 

− 8 − − + +

27 u 4 ( ) 32

27 u 1 ( ) 44

27 u 0 ( ) 11

9 u 2 ( ) 13

27 u 3 ( ) ( n + 1 ( ) -1 )

n

+

  

 

+ + − −

1

9 u 4 ( ) 4

9 u 1 ( ) 4

9 u 0 ( ) 1

3 u 2 ( ) 2

9 u 3 ( ) ( n + 1 ) 

  

 

1 +

2 n 1 ( -1 )

n

+

> rsolve({u(n+5)=u(n+4)+5*u(n+3)-u(n+2)-8*u(n+1)-4*u(n)},u,'genfunc'(x));

(13)

( )

u 0 + u 1 x ( ) + u 2 x ( )

2

+ u 3 x ( )

3

+ u 4 x ( )

4

x ( ) u 0 − u 1 x ( )

2

u 2 x ( )

3

u 3 x ( )

4

(

5 x

2

u 0 ( ) 5 x

3

u 1 ( ) 5 x

4

u 2 ( ) x

3

u 0 ( ) x

4

u 1 ( ) 8 x

4

u 0 ( )

− − − + + + ) (

+ − − + + 1 4 x

5

x 5 x

2

x

3

8 x

4

)

> solve({1/18*u(4)-7/18*u(1)-4/27*u(0)-5/18*u(2)+1/54*u(3)=0,1/54*u(4)- 5/54*u(1)-1/27*u(0)-1/18*u(2)+1/54*u(3)=0,-8/27*u(4)-32/27*u(1)-

44/27*u(0)+11/9*u(2)+13/27*u(3)=0,1/9*u(4)+4/9*u(1)+4/9*u(0)-1/3*u(2)- 2/9*u(3)=0},{u(0),u(1),u(2),u(3),u(4)});

{ u 2 ( ) = − u 3 ( ) , u 1 ( ) = u 3 ( ) , u 0 ( ) = − u 3 ( ) , u 4 ( ) = − u 3 ( ) , u 3 ( ) = u 3 ( ) } Etudions maintenant les puissances de quelques matrices stochastiques.

> Digits:=2;f:=proc(x) if abs(x)<0.01 then 0 else x;fi;end;

:=

Digits 2 :=

f proc proc proc proc( ) x if if if if abs x ( ) < .01 then then then then 0 else else else else x end if end if end if end if end proc end proc end proc end proc

> A:=matrix(3,3,[1,0,0,0.4,0.6,0,0.2,0.4,0.4]);map(f,evalm(A^100));

:=

A









1 0 0

.4 .6 0 .2 .4 .4

> A:=matrix(3,3,[0.2,0.3,0.5,0.5,0.2,0.3,0.3,0.5,0.2]);map(f,evalm(A^10));

:=

A









.2 .3 .5 .5 .2 .3 .3 .5 .2

>

A:=matrix(5,5,[1,0,0,0,0,0.5,0,0.5,0,0,0,0.5,0,0.5,0,0,0,0.5,0,0.5,0,0,0,0 ,1]);map(f,evalm(A^100));

:=

A





















1 0 0 0 0

.5 0 .5 0 0 0 .5 0 .5 0 0 0 .5 0 .5

0 0 0 0 1

>

A:=matrix(5,5,[0,1,0,0,0,0.5,0,0.5,0,0,0,0.5,0,0.5,0,0,0,0.5,0,0.5,0,0,0,1 ,0]);map(f,evalm(A^100));

:=

A





















0 1 0 0 0

.5 0 .5 0 0 0 .5 0 .5 0 0 0 .5 0 .5

0 0 0 1 0





















.16 0 .30 0 .16 0 .50 0 .50 0 .16 0 .32 0 .16

0 .50 0 .50 0 .16 0 .30 0 .16

4.3. Réduction de matrices.

> with(linalg):

> #exemple 1

> A:=matrix(3,3,[5,-3,2,6,-4,4,4,-4,5]);

:=

A









5 -3 2 6 -4 4 4 -4 5









1. 0 0 1.0 0 0 .99 0 0









.35 .35 .35 .35 .35 .35 .35 .35 .35





















1. 0 0 0 0

.73 0 0 0 .24 .49 0 0 0 .49 .23 0 0 0 .74

0 0 0 0 1.

Références

Documents relatifs

Pour pouvoir produire, chaque secteur nécessite l'utilisation d'une partie de sa propre production et d'une partie de la production de l'autre. On note : P = , E = et

Huvent, Toutes les mathématiques – Cours, exercices corrigés – MPSI, PCSI, PTSI, TSI, Ellipses,

Huvent, Toutes les mathématiques – Cours, exercices corrigés – MPSI, PCSI, PTSI, TSI, Ellipses, 2004..

(b) Démontrer que, si le nombre complexe µ est une valeur co-propre de l’application semi-linéaire u, pour tout réel θ, le nombre complexe µe i θ est encore valeur co-propre

• Le rang de AA est égal au rang de DD, donc au nombre de ses coefficients diagonaux non nuls (rang d’une matrice échelonnée), donc au nombre de | d i | 2 (donc aussi de d i )

Calculatrice autorisée (Les 4 exercices sont indépendants. Un soin tout particulier sera apporté à la rédaction des réponses)?. Exercice 1

Ce casse-tête fut posé par le mathématicien chinois Zhen Luan au VIe siècle. Il en existe diverses versions. Mais le grand Archimède avait précédé Zhen Luan et Abu Khamil

Méthode de la puissance pour trouver la plus grande valeur propre en module, ainsi qu’un vec- teur propre, vitesse