81
-2
1 0 0 0
-2
-1 0
0 0
-2 3
-1
-1
0
1 1
1
-1
-1
triu(A) - buyrug’i esa matritsaning diagonalidan
pastki qismini nollarga
aylantirishni amalga oshiradi.
Misol. Berilgan matritsaning diagonaildan pastki qismini elementlarini 0 bilan
almashtirish:
>> A=[-1 2 4 0 3; -2 1 0 3 4; -2 -1 0 -2 1; -2 3 -1 -1 1; 1 1 1 -1 -1]
A =
-1 2 4 0 3
-2 1 0 3 4
-2
-1 0 -2 1
-2 3
-1 -1 1
1 1 1 -1
-1
>>
triu(A)
ans =
-1 2 4 0 3
0
1 0 3 4
0
0
0
-2 1
0
0
0
-1 1
0
0
0
0
-1
Ushbu triu protsedurasini algoritmini o’zimiz tuzib
m-faylga yozib chiqamiz va
quyidagi natijalarga erishamiz (3.12-rasm).
3.12-rasm.
>> B=pastki(A)
x = 5
A =
-1
2 4 0 3
82
0 1 0 3 4
0 0 0
-2 1
0 0 0
-1 1
0 0 0 0
-1
RESHAPE - matrisa o’lchamini o’zgartishni amalga oshirdi.
>> A=[-1 0 2 0; 0 1 2 -1; -1 -2 -3 2]
A =
-1 0 2 0
0
1 2
-1
-1 -2
-3 2
>>
reshape(A,2,6) % matritsa elementlarining soniga qarab ixtiyoriy
o`lchamdagi matritsani hosil qiladi.
ans =
-1
-1 1 2
-3
-1
0 0
-2 2 0 2
Dostları ilə paylaş: