eolimp: Седловые точки:
https://www.eolymp.com/ru/problems/5282
Iikita matritsaning ko’paytmasini hosil qilish:
Misol: Ikki matritsaning ko’paytmasini toping.
Ikki matritsaning ko’paytmasini quyidagicha yozish mumkin
Matritsalar:
Bu yerda:
Ikki matritsaning ko’paytmasi faqat chap matritsadagi ustunlar soni o'ngdagi qatorlar soni bilan bir xil bo'lganda topish mumkin.
Dasturi:
#include
using namespace std;
int main()
{
int row1, row2, col1, col2;
double** a, ** b, ** c;
system("chcp 1251");
system("cls");
cout << "Birinchi matritsaning satrlar sonini kiriting: ";
cin >> row1;
cout << "Birinchi matritsaning ustunlar sonini kiriting: ";
cin >> col1;
cout << "Ikkinchi matritsaning satrlar sonini kiriting: ";
cin >> row2;
cout << "Ikkinchi matritsaning ustunlar sonini kiriting: ";
cin >> col2;
if (col1 != row2)
{
cout << "Ko'paytirib bo'lmaydi!";
cin.get(); cin.get();
return 0;
}
// Birinchi matritsani kiritish
a = new double* [row1];
cout << "Birinchi matritsaning elementlarini kiriting:" << endl;
for (int i = 0; i < row1; i++)
{
a[i] = new double[col1];
for (int j = 0; j < col1; j++)
{
// cout << "a[" << i << "][" << j << "]= ";
cin >> a[i][j];
}
}
// Ikkinchi matritsani kiritish
b = new double* [row2];
cout << "Ikkinchi matritsaning elementlarini kiriting:" << endl;
for (int i = 0; i < row2; i++)
{
b[i] = new double[col2];
for (int j = 0; j < col2; j++)
{
// cout << "b[" << i << "][" << j << "]= ";
cin >> b[i][j];
}
}
// Matritsalar ko'paytmasi:
c = new double* [row1];
for (int i = 0; i < row1; i++)
{
c[i] = new double[col2];
for (int j = 0; j < col2; j++)
{
c[i][j] = 0;
for (int k = 0; k < col1; k++)
c[i][j] += a[i][k] * b[k][j];
}
}
// Ko'paytma matritsani chiqarish:
cout << "Matritsalar ko'paytmasi:" << endl;
for (int i = 0; i < row1; i++)
{
for (int j = 0; j < col2; j++)
cout << c[i][j] << " ";
cout << endl;
}
}
Natija:
Mustaqil yechish uchun: Algo: 0140. Matritsa11
Kvadrat matritsaning determinantini topish.
Kvadrat matritsaning determinanti (determinanti) bu matritsaga tayinlangan va quyidagi qoidalarga muvofiq uning elementlaridan hisoblangan son.
Birinchi tartibli matritsa uchun determinantning qiymati ushbu matritsaning yagona elementiga teng:
2X2 lik matritsa uchun:
nXm lik matritsa uchun esa:
Bu erda Mij kvadrat matritsaning qo'shimcha minori - i-qator va j-ustunni o'chirish orqali asl nusxadan olingan matritsaning determinanti.
Masalan, 3-tartibli matritsaning determinantini hisoblash formulasi:
Dasturi:
#include
#include
#include
using namespace std;
int main(){
const double EPS = 1E-9;
int n;
cout<<"Kvadrat matritsa o'lchamini kiriting: ";
cin>>n;
vector < vector > a (n, vector (n));
cout<<"Kvadrat matritsa o'elementlarini kiriting:\n";
for(int i=0; ifor(int j=0; jcin>>a[i][j];
}
}
double det = 1;
for (int i=0; i int k = i;
for (int j=i+1; j if (abs (a[j][i]) > abs (a[k][i]))
k = j;
if (abs (a[k][i]) < EPS) {
det = 0;
break;
}
swap (a[i], a[k]);
if (i != k)
det = -det;
det *= a[i][i];
for (int j=i+1; j a[i][j] /= a[i][i];
for (int j=0; j if (j != i && abs (a[j][i]) > EPS)
for (int k=i+1; k a[j][k] -= a[i][k] * a[j][i];
}
cout <<"Matritsa determinanti: "<< det<}
Natija:
5-topshiriq
Matritsani matritsaga ko’paytirish dasturi tuzilsin.
|
Kiruvchi ma’lumotlar: Birinchi satrda N va M birinchi matritsao’lchamlari(1<=N,M <=50). Keyingi N satrda M ta butun son birinchi matritsaelementlari (-100<=a[i,j]<=100). Keyingi satrda X va Y ikkinchi matritsao’lchamlari (1<=X,Y<=50) keying X satrda Y butun son ikkinchi matritsaelementlari (M=X);
Chiquvchi ma’lumotlar: xosil bo’lgan matritsa
|
Kiruvchi ma’lumotlar
|
Chiquvchi ma’lumotlar
|
2 3
57 17 54
86 4 52
3 6
93 87 74 26 15 72
37 67 96 6 96 94
24 79 63 38 21 63
|
7226 10364 9252 3636 3621 9104
9394 11858 10024 4236 2766 9844
|
2 3
62 40 15
63 50 6
3 2
36 52
21 59
4 66
|
3132 6574
3342 6622
|
|
Dastur kodi:
#include
using namespace std;
int main()
{
int n,m,x,y;
cout<<"A-matritasni ustun va satr o'lchamini kiriting:"; cin>>n>>m;
int a[n+1][m+1];
cout<<"A matritsani elementlarini kiriting: \n";
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
cin>>a[i][j];
cout<<"B-matritasni ustun va satr o'lchamini kiriting:"; cin>>x>>y;
int b[x+1][y+1],c[n+1][y+1]={0},mn;
for(int i=1; i<=x; i++)
for(int j=1; j<=y; j++)
cin>>b[i][j];
cout<<"A matritsani elementlari...\n";
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
cout<cout<}
cout<<"B matritsani elementlari...\n";
for(int i=1; i<=x; i++)
{
for(int j=1; j<=y; j++)
cout<cout<}
for(int i=1; i<=n; i++)
{
for(int j=1; j<=y; j++)
{
for(int s=1; s<=m; s++)
c[i][j]+=a[i][s]*b[s][j];
}
}
cout<<"'A*B' yani C matritsa... \n";
for(int i=1; i<=n; i++)
{
for(int j=1; j<=y; j++)
cout<cout<}
}
Do'stlaringiz bilan baham: |