I have a while loop, in which I use a Matrix A, vectors B and x with varying dimensions:

int count=0;

MatrixXd A(count,2*count);
VectorXd B(2*count);

// assignment of A, and B

VectorXd x = A.householderQr().solve(B);

// output of x

if (x.norm()>30)


However the program built this way always collapses. I tried to use pointers to such matrices or vector, and got similar failures.

How can I handle such issue?

  • $\begingroup$ You may need to deallocate the memory before changing the dimensions of the matrix. What library are you using for your matrices/vectors? $\endgroup$
    – Paul
    Commented Dec 4, 2013 at 16:14
  • 2
    $\begingroup$ What do you mean by "collapse"? $\endgroup$
    – ggael
    Commented Dec 4, 2013 at 17:05

1 Answer 1


You have a size mismatch issue: A is a count x 2*count matrix, and you are trying to solve Ax=B with B a 2*count x 1 vector.

Moreover, if you compile without -DNDEBUG, you should get a nice assertion telling you this is wrong.

To resize a matrix or vector:

A.resize(count, 2*count);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.