A 2×2 real and symmetric matrix representing a stretching and shearing of the plane. Rcpp integration for the Eigen templated linear algebra library. Std::cout << "Compare with the result using an rotation matrix " << std::endl << R * v << std::endl Įigen::Quaterniond a = Eigen::Quterniond::Identity() Įigen::Quaterniond b = Eigen::Quterniond::Identity() Įigen::Quaterniond c // Adding two quaternion as two 4x1 vectors is not supported by the EIgen API. The blue arrow is an eigenvector of this shear mapping because it does not change direction, and since its length is unchanged, its eigenvalue is 1. Std::cout << "We can now use it to rotate a vector " << std::endl << v << " to " << std::endl << rotatedV << std::endl Įigen::Matrix3d R = q.toRotationMatrix() // convert a quaternion to a 3x3 rotation matrix The equality of these eigen vectors is an artefact imposed by the two dimensional limit. Std::cout << "To represent rotation, we need to normalize it such that its length is " << q.norm() << std::endl Įigen::Quaterniond rotatedP = q * p * q.inverse() Įigen::Vector3d rotatedV = rotatedP.vec() Std::cout << "This quaternion consists of a scalar " << q.w() << " and a vector " << std::endl << q.vec() << std::endl
(Naturally, real eigenvalues have corresponding.
Std::cout << "Take sub-matrix whose upper left corner is A(1, 2)" << std::endl << B << std::endl Įigen::VectorXd a = A.col(1) // take the second column of AĮigen::VectorXd b = B.row(0) // take the first row of BĮigen::VectorXd c = a.head(3) // take the first three elements of aĮigen::VectorXd d = b.tail(2) // take the last two elements of b Numerically, Ive found that every eigenvector corresponding to a complex eigenvalue has a single real element. Std::cout << "The element at fourth row and 7the column is " << A(3, 6) << std::endl We find two corresponding eigenvectors and plot them in the plane. Std::cout << "The multiplication of B * b is " << std::endl << Bb << std::endl Įigen::MatrixXd B = A.transpose() // the transpose of A is a 2x3 matrixĮigen::MatrixXd C = (B * A).inverse() // computer the inverse of BA, which is a 2x2 matrixĭouble vDotw = v.dot(w) // dot product of two vectorsĮigen::Vector3d vCrossw = v.cross(w) // cross product of two vectorsĮigen::MatrixXd A = Eigen::MatrixXd::Random(7, 9) Suppose that the eigenvalues of P are real and positive. Std::cout << "The multiplication of A * a is " << std::endl << Aa << std::endl Įigen::MatrixXd B = Eigen::MatrixXd::Identity(6, 5) eigenspaces thus have 1, 2, and 3 linearly independent eigenvectors, respectively. Eigen::Matrix3d A = Eigen::Matrix3d::Identity()