|
Izoh: matritsaning satrlari soni vektorning satrlariga teng bo’lishi kerak
|
tarix | 07.01.2024 | ölçüsü | 12,91 Kb. | | #204677 |
| A matritsani B vektorga ko’paytirish algoritmi
1-misol. A matritsani B vektorga ko’paytirish algoritmi. S i =
Izoh: matritsaning satrlari soni vektorning satrlariga teng bo’lishi kerak.
Masalan: 1 2 3 1
A = 4 5 6 B = 3
7 8 9 6
C1= 1*1+2*3+3*6 = 25
C2 = 4*1+5*3+6*6 = 55
C3 = 7*1+8*3+9*6 = 85
# include
# include
using namespace std;
int main ( )
{
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, b[3]= {1,3,6}, c[3], i, j;
cout<
for (i=0; i<3; i++)
{ c[i] = 0;
for (j=0; j<3; j++)
c[i] = c[i] + a[i][j] * b[j];
cout <<" C["<
getch ( );
}
2-misol. Matritsani transponirlash algoritmini tuzing. Matritsani transponirlash deb, ustun va satr elementlarini o’zaro o’rin almashtirishga aytiladi, ya`ni Aij = Bji
Berilgan matritsa:
1 2 3
4 5 6
7 8 9
Hosil bo’lgan matritsa:
1 4 7
2 5 8
3 6 9
# include
# include
using namespace std;
int main ( )
{
int a[3][3] = {{1,2,3},{4,5,6},{7,8,9}}, b[3][3], i, j;
cout<
for ( i=0; i<3; i++)
{ for ( j=0; j<3; j++)
{ b[i][j] = a[j][i];
cout <<" b["<
cout << endl; }
getch ( );
}
Dostları ilə paylaş: |
|
|