SSE value calculated in C++ eigen is different from true value

I am a beginner of C++. Any help will be very appreciated!
I can successfully compile and run the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <Eigen/Dense>
#include <iostream>
#include <cmath>
using namespace Eigen;

int main()
{
  MatrixXf m1(10,1);
  m1 << 50,51,52,54,53,60,59,65,67,70;
  MatrixXf m3(3,10);
  MatrixXf m2(10,3);
  m3<< 1,1,1,1,1,1,1,1,1,1,     //Xf[,5:6]
       54,61,52,70,63,0,0,0,0,0,
       0,0,0,0,0,79,68,65,79,76;
  m2 << m3.transpose();
  MatrixXf I(10,10);
  I.setIdentity(10,10);
  float SSE =(m1.transpose()*(I-m2*(m2.transpose()*m2).inverse()*m2.transpose())*m1).determinant();
  std::cout << "SSE=" << std::endl;
  std::cout << SSE << std::endl << std::endl;
  system("pause");
}




SSE worked out in C++:87.7938
SSE true value:88.29133
Last edited on
Looks like float imprecision problem. Try to use MatrixXd and check if the problem persist.
@MiiNiPaa thank you, i have got the answer. MatrixXd is more precision, and it got the same value from the true value.
Last edited on
Topic archived. No new replies allowed.