|
Mustaqil ish fan: Amaliy dasturiy paketlar
|
bet | 4/8 | Sana | 27.05.2024 | Hajmi | 232,03 Kb. | | #255039 |
Bog'liq Matlab tizimida matritsalar ustida arifmetik amallar bajarish-2 1 0
2 2 1
Endi shu amalni algoritmi haqida ya’ni o’z qo’limiz yordamida bajaramiz:
>> for i=1:3; for j=1:3; C(i,j)=0; for k=1:3; C(i,j)=C(i,j)+A(i,k)*B(k,j); end; end; end; C
C =
2 -1 1
-2 1 0
2 2 1
diag(A) buyrug’i berilgan matritsaning diagonalida tugan elementlarni ekranga chiqaradi:
>> A=[-1 0 1; 0 -1 0; 1 -1 1]
A =
-1 0 1
0 -1 0
1 -1 1
>> diag(A)
ans =
-1 % A matritsaning dioganal elementlarini ustun ko`rinishida chiqaradi.
-1
1
1
Shu amalni o’zimiz bajarib chqamiz:
>> for i=1:3; D(i)=A(i,i);end; D
D = -1 -1 1
eye(n) buyrug’i birlik matritsani hosil qiladi.
Misol.
>> eye(5)
ans =
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Endi shu matritsani m-faylga funksiyasini yaratamiz. Ushbu m-faylga birlik matritsa hosil qiladigan protsedura yasadik va uning nomini diagonal.m deb nomladik. Endi bu m-fayl yordamida diagonal(n) buyrug’i hosil bo’ldi.
Endi ushbu buyruq yordamida ham eye(n) buyrug’ining bajargan ishini bajarsa bo’ladi:
>> diagonal(5)
ans =
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
tril (A) - berilgan matritsaning diagonaildan yuqori qismini elementlarini 0 bilan almashtirishni amalga oshiradi.
Misol. Berilgan matritsaning diagonaildan yuqori 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
|
| |