-4

I am trying a program in with eigen library in C++ but making some mistake in syntax part. Here is my code. Can someone comment where I went wrong?

#include <iostream>
#include <Eigen\Dense> //EIGEN library

using namespace Eigen;
using namespace std;

int main()
{
  Matrix<double,2000,2000> A;
  Matrix<double,2000,2000> B;
  Matrix<double,2000,2000> C;

  A.setRandom(2000,2000);
  B.setRandom(2000,2000);

  //A = Dynamic2D::Random(rows, cols);
  // A<<MatrixXd::Identity(2000,2000);

  C=A*B;
}

Also what is wrong is declaring matrix A as given in comment lines?

//A = Dynamic2D::Random(rows, cols);
// A<<MatrixXd::Identity(2000,2000);
Rakib
  • 7,435
  • 7
  • 29
  • 45
user3705273
  • 325
  • 6
  • 14

1 Answers1

0

When the matrix dimensions are specified as template parameters Eigen will attempt to allocate the storage space of the stack. Unfortunately the stack isn't big enough to accommodate 4 million doubles. For large matrices it's best to use instead dynamic size:

MatrixXd A; A.setRandom(2000, 2000);

You can initialize A as the identity matrix using the assignment operator instead of <<:

A = MatrixXd::Identity(2000,2000);

Benoit Steiner
  • 1,484
  • 11
  • 11