-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorthogonal_matrix.cpp
84 lines (82 loc) · 1.76 KB
/
orthogonal_matrix.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "enter the number of row/column of square matrix: ";
cin >> n;
int a[n][n];
cout << "enter the elements: ";
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cin >> a[i][j];
}
}
cout << "your matrix is: " << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
// transpose
cout << "transpose of the matrix: " << endl;
int b[n][n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
b[i][j] = a[j][i];
cout << b[i][j] << " ";
}
cout << endl;
}
// multiplication
cout << "multiplication of matrix and it's transpose: " << endl;
int c[n][n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
int sum = 0;
for (int k = 0; k < n; k++)
{
sum = sum + a[i][k] * b[k][j];
}
c[i][j] = sum;
cout << c[i][j] << " ";
}
cout << endl;
}
// orthogonal check
int count = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (i == j)
{
if (a[i][j] == 1)
{
count++;
}
}
else if (a[i][j] == 0)
{
count++;
}
}
}
cout << endl;
if (count == 2 * n)
{
cout << "***matrix is orthogonal***" << endl;
}
else
cout << "***matrix is not orthogonal***" << endl;
return 0;
}