हैंकेल मैट्रिक्स क्या है?
एक वर्ग मैट्रिक्स जहां प्रत्येक आरोही तिर्यक विकर्ण (skew-diagonal) के तत्व स्थिर होते हैं। अर्थात mat[i][j] केवल i+j पर निर्भर करता है।
उदाहरण
1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 4 5 6 7 8 5 6 7 8 9
जांच नियम
mat[i][j] = a[i+j] जहां:
- यदि i+j < n: a[i+j] = mat[i+j][0]
- अन्यथा: a[i+j] = mat[i+j-n+1][n-1]
उदाहरण कोड
#include <iostream>
#define N 5
using namespace std;
bool isHankelMat(int mat[N][N], int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i + j < n) {
if (mat[i][j] != mat[i + j][0]) return false;
} else {
if (mat[i][j] != mat[i + j - n + 1][n - 1]) return false;
}
}
}
return true;
}
int main() {
int n = 5;
int mat[N][N] = {
{1, 2, 3, 4, 5},
{2, 3, 4, 5, 6},
{3, 4, 5, 6, 7},
{4, 5, 6, 7, 8},
{5, 6, 7, 8, 9}
};
if (isHankelMat(mat, n))
cout << "This is Hankel Matrix";
else
cout << "This is not Hankel Matrix";
return 0;
}
आउटपुट
This is Hankel Matrix