Vous êtes sur la page 1sur 2

UMMTO

Faculté des Sciences Tronc Commun Mathématiques et d'Informatique


Mr A.Amirou TPN°3:Outils de Programmation1___2021/2022____________________________
Solutions TP_N°3:

Exercice1: Exercice4: Exercice6:


1. >>v=[-5:5]
v = -5 -4 -3 -2 -1 0 1. >> linspace(1,20,5) 1. >> A=[1 2 3; 0 5 4; 7 0 9 ];
1 2 3 4 5 ans =1.0000 5.7500 10.5000 >> B=[5 4 ; 0 9 ];
2. >> V=[-500:500]' 15.2500 20.0000 2. >> v= diag (A), b=diag (v),
V = -500 2. >> ones(1,9) c=diag ( diag (A))
.... ans = 1 1 1 1 1 v= 1
500 1 1 1 1 5
3. >> V=[0:0.2:1] 3. >> 31*ones(3,3) 9
V = 0 0.2000 0.4000 ans = b=
0.6000 0.8000 1.0000 31 31 31 1 0 0
4. >> x=[- 31 31 31 0 5 0
1.3,sqrt(3),(1+2+3)*4/5] 31 31 31 0 0 9
x = -1.3000 1.7321 4. >> 2*eye(3) c=
4.8000 ans = 1 0 0
2 0 0 0 5 0
Exercice2: 0 2 0 0 0 9
1. >>V = 8 1 13 4 0 0 2 3. >> A( 1 : 2 , : ), A( : , 2 : 3 ),
7 6 A( 1 : 2 , 2 : 3 )
>>V=V'; Exercice5: ans = 1 2 3
2. >> V(2) 1. >> Mat=[v ;2*v;3*v;4*v] 0 5 4
ans = 1 ans = 2 3
3. >> V(2:4) Mat =
-1 -3 -5 -7 5 4
ans = 1 13 4
-2 -6 -10 -14 0 9
4. >> V(5:-2:1)
ans = 7 13 8 ans = 2 3
-3 -9 -15 -21
5. >> V(3:end) 5 4
-4 -12 -20 -28 4. >> B=A(2:3,2:3)
ans = 13 4 7
6
2. >> diag(A) B= 5 4
6. >> V(1) ans = 0 9
ans = 8 1 5. >> A( 1 : 2 , 1 : 2 : 3 ), A( 1 :
7. >> V(7)=-3 5 2:3,1:2:3)
V = 8 1 13 4 7 9 ans = 1 3
6 -3 3. >> tril( A) , triu(A ) 0 4
ans =1 0 0 ans =1 3
Exercice3: 7 9
0 5 0
>> x=[1 2 3]; >> y=[4 5 6];
7 0 9
1. >> x=x+3
ans = 1 2 3
x= 4 5 6
2. >> x=x-5 0 5 4
x = -1 0 1 0 0 9
3. >> x-y
ans = -5 -5 -5
4. >> x.*y
ans = -4 0 6
5. >> x./y
ans = -0.2500
0 0.1667
6. >> x.^y
ans = 1 0 1

1
UMMTO
Faculté des Sciences Tronc Commun Mathématiques et d'Informatique
Mr A.Amirou TPN°3:Outils de Programmation1___2021/2022____________________________

Exercice7: Exercice9: Exercice10:

>> M = [1,2] * [3 ;4] >> M=[12 24 36 58 ; 2 6 >> x=[2 15 0]


8 10; 7 2 1 3 ]
M= M= x=
12 24 36 58
2 6 8 10 2 15 0
11
7 2 1 3
>> M(3 ,4) >> sort(x)
>> P = [1 ;2] * [3,4] ans =
3 ans =
P= >> L3=M(3,:)
L3 = 0 2 15
3 4 7 2 1 3
6 8 >> C4=M(:,4) >> sort(x')
C4 =
>> , Q = [1,2] *[3,4] 58 ans =
Inner matrix dimensions must 10
agree. 3 0
>> M1=M( 2:3, 2:3) 2
M1 = 15
Exercice8: >> sum(x)
6 8
2 1
 >> jan=[ 3 2 1 5 2], >> M2=M(end:-1:1,:) ans =
feb=[2 3 1 3 3], M2 =
march=[ 1 0 3 3 3] 7 2 1 3 17
jan = 2 6 8 10
3 2 1 5 2 12 24 36 58 >> max(x)
feb = >> M2=[M(3,:) ; M(2,:) ;
2 3 1 3 3 M(1,:)] ans =
march = M2 =
7 2 1 3 15
1 0 3 3 3
2 6 8 10
>> quality=[jan; feb; march] >> min(x)
12 24 36 58
quality =
3 2 1 5 2 ans =
2 3 1 3 3
1 0 3 3 3 0
 . >> size(quality)
ans =
3 5
 >> length(quality)
ans =
5

Vous aimerez peut-être aussi