TP1: initialisation a la programmation avec Matlab
Derigee par : en cadre
par :
Mohamed Maline Mr Facoiti
Mohamed Mechache
Imad Jellal
G4
Introduction à MATLAB
MATLAB est un logiciel de calcul matriciel à syntaxe simple. Avec
ses fonctions spécialisées, MATLAB peut être aussi considéré
comme un langage de programmation adapté pour les problèmes
scientifiques. MATLAB est un interpréteur : les instructions sont
interprétées et exécutées ligne par ligne. MATLAB fonctionne dans
plusieurs environnements tels que Xwindows, Windows, Macintosh
EXERCICE 1 :
1) La fonction qui permet de calculer les valeurs propre et vecteur
propre d’une matrice care.
A= [5 -3 ; 6 -4]
A=
5 -3
6 -4
>> eig(A)
ans =
-1
1) sa syntaxe
>> help eig
eig - Eigenvalues and eigenvectors
This MATLAB function returns a column vector containing the eigenvalues, with
multiplicity, that satisfy the equation Av = λv, where A is an n-by-n matrix, v
is a column vector of length n, and λ is a scalar.
lambda = eig(A)
lambda = eig(A,balanceOption)
lambda = eig(A,B)
lambda = eig(A,B,algorithm)
[V,D] = eig(___)
[V,D,W] = eig(___)
[___] = eig(___,eigvalOption)
Reference page for eig
See also balance, condeig, eigs, hess, qz, schur
>> [V;D]=eig(A)
[V;D]=eig(A)
Error: Multiple left-hand sides must be separated by
commas.
>> [V,D]=eig(A)
V=
0.7071 0.4472
0.7071 0.8944
D=
2 0
0 -1
2) creer de deux facons le vecteure ligne (9 ;7 ;5 ;3 ;1)
a) Premier façon
>> A=[ 9 7 5 3 1 ]
A=
9 7 5 3 1
b) deuxiemefacon
>> A=[9:-2:1]
A=
9 7 5 3 1
3) créer de deux façon le vecteur colonne(10 ;9,5 ;9 ;8.5 ;8)^t.
a) Premier façon.
>> B=[10;9.5;9;8.5;8]
B=
10.0000
9.5000
9.0000
8.5000
8.0000
b) deuxième façon.
>> B=[10:-0.5:8]'
B=
10.0000
9.5000
9.0000
8.5000
8.0000
>> C=[A A A]
C=
9 7 5 3 1 9 7 3 1 9 7 5 3 1
>> D=[B;B;B]
D=
10.0000
9.5000
9.0000
8.5000
8.0000
10.0000
9.5000
9.0000
8.5000
8.0000
10.0000
9.5000
9.0000
8.5000
8.0000
EXERCICE 2:
1. sert la function reshape,
>> help reshape
reshape - Reshape array
This MATLAB function or B = reshape(A,[m n]) returns the m-by-n matrix B whose
elements are taken column-wise from A.
B = reshape(A,m,n)
B = reshape(A,[m n])
B = reshape(A,m,n,p,...)
B = reshape(A,[m n p ...])
B = reshape(A,...,[],...)
Reference page for reshape
See also circshift, colon (:), permute, repmat, shiftdim, squeeze
Exemples.
>> A=1:10
A=
1 2 3 4 5 6 7 8 9 10
>> reshape(A,5,2)
ans =
1 6
2 7
3 8
4 9
5 10
Exercice 3:
1)
>> A=[ 2 3 4 ; 1 -1 -1 ; -1 4 1 ]
A=
2 3 4
1 -1 -1
-1 4 1
>> B=[3;0;5]
B=
>> X=inv(A)*B
X=
0.7778
1.6667
-0.8889
>> A\B
ans =
0.7778
1.6667
-0.8889
Exercice 4:
>> A=[1 -1 7 4 ;-4 2 11 -1 ;8 0 3 2 ; 1 5 -2 1 ]
A=
1 -1 7 4
-4 2 11 -1
8 0 3 2
1 5 -2 1
>> B=[5 -1 1 -2;-1 0 11 8;3 -3 3 1;2 1 -2 -1]
B=
5 -1 1 -2
-1 0 11 8
3 -3 3 1
2 1 -2 -1
>> 3*A
ans =
3 -3 21 12
-12 6 33 -3
24 0 9 6
3 15 -6 3
>> A.B
Attempt to reference field of non-structure array.
>> A*B
ans =
35 -18 3 -7
9 -30 53 36
53 -15 13 -15
-4 6 48 35
>> A.*B
ans =
5 1 7 -8
4 0 121 -8
24 0 9 2
2 5 4 -1
>> A./B
ans =
0.2000 1.0000 7.0000 -2.0000
4.0000 Inf 1.0000 -0.1250
2.6667 0 1.0000 2.0000
0.5000 5.0000 1.0000 -1.0000
>> cos(A)
ans =
0.5403 0.5403 0.7539 -0.6536
-0.6536 -0.4161 0.0044 0.5403
-0.1455 1.0000 -0.9900 -0.4161
0.5403 0.2837 -0.4161 0.5403
>> exp(B)
ans =
1.0e+04 *
0.0148 0.0000 0.0003 0.0000
0.0000 0.0001 5.9874 0.2981
0.0020 0.0000 0.0020 0.0003
0.0007 0.0003 0.0000 0.0000
Exercice 5: