Reputation: 558
I am trying to find eigen values for a syymetric matrix as follows:-
Mat t(2, 2, CV_32F);
t.at<float>(0, 0) = 1;
t.at<float>(0, 1) = 0;
t.at<float>(1, 0) = 0;
t.at<float>(1, 1) = 128;
Mat eigVal,eigVec;
eigen(t,eigVal,eigVec);
When I am printing the eigen values for this matrix it gives me correct answer.
cout << eigVal.at<float>(0) << "," << eigVal.at<float>(1) << "\n";
The output which I get is 128,1. But when I am changing my matrix as follows:-
t.at<float>(0, 0) = 4;
t.at<float>(0, 1) = 2;
t.at<float>(1, 0) = 1;
t.at<float>(1, 1) = 3;
I am not getting correct response. The output which I am expecting is 5,2. But instead I am getting output as 5.56155 and 1.43845. Can anyone tell me where I did mistake
Upvotes: 0
Views: 107
Reputation: 4209
eigen
only works on symmetric matrices (those with equal values of either side of the main diagonal). You need eigenNonSymmetric
for non-symmetric matrices:
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(int argc, char *argv[])
{
Mat t(2, 2, CV_32F);
t.at<float>(0, 0) = 4;
t.at<float>(0, 1) = 2;
t.at<float>(1, 0) = 1;
t.at<float>(1, 1) = 3;
Mat eigVal,eigVec;
eigenNonSymmetric(t,eigVal,eigVec);
cout << eigVal.at<float>(0) << "," << eigVal.at<float>(1) << "\n";
return 0;
}
Output:
5,2
Upvotes: 1