Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Solve Complex Linear Algebra Problems With Eigen C++ Library

Since we learn C and C++ at university, we happen to get many projects related to Applied Math and Linear Algebra. And we should build an application to solve different complex problems with C/C++ (mostly C++). I have tried to implement some functions, for instance, dot product and cross product functions and also several matrix elimination functions. But, while stuck on implementing some methods with C++, I found the Eigen C++ library which is a C++ template library for linear algebra: matrices, vectors, numerical solvers, and related algorithms. 

Eigen library helped me to save dozens of hours! You can get the Eigen library from GetIt and utilize it with C++ Builder projects easily.

Here is some sample source code from the Eigen Array Of String test:

EIGEN_DECLARE_TEST(array_of_string)
{
  typedef Array<std::string,1,Dynamic> ArrayXs;
  ArrayXs a1(3), a2(3), a3(3), a3ref(3);
  a1 << "one", "two", "three";
  a2 << "1", "2", "3";
  a3ref << "one (1)", "two (2)", "three (3)";
  std::stringstream s1;
  s1 << a1;
  VERIFY_IS_EQUAL(s1.str(), std::string("  one    two  three"));
  a3 = a1 + std::string(" (") + a2 + std::string(")");
  VERIFY((a3==a3ref).all());

  a3 = a1;
  a3 += std::string(" (") + a2 + std::string(")");
  VERIFY((a3==a3ref).all());

  a1.swap(a3);
  VERIFY((a1==a3ref).all());
  VERIFY((a3!=a3ref).all());
}

Head over and find out more about Eigen in Embarcadero GetIt and then download it via the IDE.

Get the answers to the most intriguing questions about the std string method as well as String Operations in C++ software in this article.

Exit mobile version