السلام عليكم ورحمه الله .... جمعة مباركه علي الجميع
اخوتي طلب مني برنامج بلغه ++c علي المصفوفات البولينيه boolean matrix , مثلاً إذا كان
1 A = 0 0
1 1 0
B = 1 1 1
1 1 1
0 0 0
من ثم الخرج يكون X
X = 1 1 1
1 1 1
علي حسب فهمي للمساله :wink: : اوجدت منقول المصفوفه A و من ثم ضربتها في معكوس المصفوفه B واخيرا حسبت معكوس الناتج و كانت النتيجه قيم X :wacko:
ومنها كتبت برنامجي ولكن لايعمل :sad:
اتمني ان اجد المساعده في البرنامج ولكم مني كل الشكر والتقدير وجزاكم الله الف خير
وهذا هو البرنامج :=
#include <cstdlib>
#include <cstdio>
#include<iostream>
using namespace std;
#define MAX 10
void transpose(float *A, int m, int n);
void inverse(float *AT, int ra, int ca);
void multiply(
int* A, //first matrix
int ra, //first matrix rows
int* B, //second matrix
int cb, //second matrix columns
int sh, //SHARED DIMENSION as 'first' columns and 'second' rows MUST BE THE SAME
int* X //to store the result
);
void get_mat(float *m, int &X, int &c);
void disp(float* m, int X, int c);
void multiply(float* AI, int ra, float* B, int cb, int sh, float* X);
float a[10][10];
float b[10][10];
float c[10][10];
int main()
{
float *A, *AI, *AT, *B, *X;
int ra, ca; // rows and columns for matrix ai
int rb, cb; // rows and columns for matrix b
int i, j;
cout << "First matrix size(rows columns) = ";
cin >> ra >> ca;
cout << "Second matrix size(rows columns) = ";
cin >> rb >> cb;
//if (ca != rb){
// cout << "Error: The matrices cannot be multilplied, size mismatch.";
// return 0;
//}
A = new float[ra * ca];
AT = new float[ra * ca];
AI = new float[ra * ca];
B = new float[rb * cb];
X = new float[ra * cb];
get_mat(A, ra, ca);
get_mat(B, rb, cb);
cout << "Original matrix\n";
disp(A, ra, ca);
for (i = 0; i < ca; i++)
for (j = 0; j < ra; j++)
{
a[j] = A[ca * i + j];
cout << a[j] << "\n";
}
//TRANSPOSE
transpose(A, ra, ca);
cout << "Transposed matrix\n";
for (i = 0; i < ca; i++)
for (j = 0; j < ra; j++)
{
AT[ca * i + j] = a[j];
cout << AT[ca * i + j] << "\n";
}
//INVERSE
inverse(AT, ra, ca);
cout << "Inverse matrix\n";
for (i = 0; i < ca; i++)
for (j = 0; j < ra; j++)
{
AI[ca * i + j] = b[j];
cout << AI[ca * i + j] << "\n";
}
//MULTIPLY
multiply(AI, ra, B, cb, ca, X);
cout << "\n\nResult = \n";
disp(X, ra, cb);
cout << "\nResult Transpose = \n";
disp(AT, ra, ca);
cout << "\nResult Inverse = \n";
disp(AI, ra, ca);
cout << "Press any key to exit...";
// getch();
delete[] A;
delete[] AT;
delete[] AI;
return 0;
}
void transpose(float *A, int m, int n)
{
int i, j;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
{
a[j] = A[n * i + j];
cout << a[j] << "\n";
}
cout << endl << "Displaying Matrix Transpose: " << endl << endl;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
cout << a[j] << " ";
}
cout << endl << endl;
}
getch();
}
void inverse(float *AT, int ra, int ca)
{
float d, m;
int i, j, k;
for (i = 0; i < ra; i++)
for (j = 0; j < ca; j++)
{
a[j] = AT[ca * i + j];
cout << a[j] << "\n";
}
for (i = 0; i < ca; i++)
{
for (j = 0; j < ra; j++)
{
if (i == j)
b[j] = 1;
else
b[j] = 0;
}
}
if (a[0][0] == 0)
{
for (j = 0; j < ca; j++)
{
c[0][j] = b[1][j];
c[0][j] = a[1][j];
a[1][j] = a[0][j];
a[0][j] = c[0][j];
b[1][j] = b[0][j];
b[0][j] = c[0][j];
}
}
for (i = 0; i < ca; i++)
{
d = a;
for (j = 0; j < ra; j++)
{
a[j] = a[j] / d;
b[j] = b[j] / d;
}
for (k = 0; k < ca; k++)
{
if (k != i)
{
m = a[k];
for (j = 0; j < ra; j++)
{
a[k][j] = a[k][j]-(a[j] * m);
b[k][j] = b[k][j]-(b[j] * m);
}
}
}
}
cout << "\nInverse of matrix is:\n";
for (i = 0; i < ca; i++)
{
for (j = 0; j < ra; j++)
printf(" %f ", b[j]);
printf("\n");
}
getch();
}
void get_mat(float *m, int &X, int &c)
{
cout << "Enter [" << X << "x" << c << "] Matrix :\n";
for (int i = 0; i < X * c; i++)
cin >> m;
}
void multiply(float* AI, int ra, float* B, int cb, int sh, float* X)
{
for (int i = 0; i < ra * cb; ++i)
{
X = 0;
for (int j = 0; j < sh; ++j)
X += AI[(i / cb) * sh + j] * B[i % cb + j * cb];
if (X > 1)
{
X = 1;
}
}
}
void disp(float* m, int X, int c)
{
for (int i = 0; i < X * c; i++)
{
!(i % c) && cout << endl;
cout << m << '\t';
}
cout << endl;
}
//getchar();
//getchar();
= ';



