Search code examples
c++eigeneigen3

Frobenius Inner Product between two matrices in Eigen3


Is there a simple and quick solution to calculate the Frobenius Inner Product between two 3x3 matrices in Eigen3?


Solution

  • If you are searching for the inner product of matrices, a possible (maybe not optimal) solution may be

        #include <iostream>
        #include "Eigen/Dense"
         
        int main()
        {
          
        Eigen::Matrix3d A, B;
        A << 1, 2, 3,
                4,5,6,
                7,8,9;
        B << 10, 11, 12,
                 13,14,15,
                 16,17,18;
    
        Eigen::Matrix3d C;
        C = A.transpose()*B;
        
        std::cout << C.trace() << std::endl;
    
            return 0;
        }