Eigen 中矩阵的定义
#include <Eigen/Dense>
Matrix<double, 3, 3> A;
Matrix<double, 3, Dynamic> B;
Matrix<double, Dynamic, Dynamic> C;
Matrix<double, 3, 3, RowMajor> E;
Matrix3f P, Q, R;
Vector3f x, y, z;
RowVector3f a, b, c;
VectorXd v;
x.size()
C.rows()
C.cols()
x(i)
C(i,j)
Eigen 中矩阵的使用方法
A.resize(4, 4);
B.resize(4, 9);
A.resize(3, 3);
B.resize(3, 9);
A << 1, 2, 3,
4, 5, 6,
7, 8, 9;
B << A, A, A;
A.fill(10);
Eigen 中常用矩阵生成
MatrixXd::Identity(rows,cols)
C.setIdentity(rows,cols)
MatrixXd::Zero(rows,cols)
C.setZero(rows,cols)
MatrixXd::Ones(rows,cols)
C.setOnes(rows,cols)
MatrixXd::Random(rows,cols)
C.setRandom(rows,cols)
VectorXd::LinSpaced(size,low,high)
v.setLinSpaced(size,low,high)
Eigen 中矩阵分块
x.head(n)
x.head<n>()
x.tail(n)
x.tail<n>()
x.segment(i, n)
x.segment<n>(i)
P.block(i, j, rows, cols)
P.block<rows, cols>(i, j)
P.row(i)
P.col(j)
P.leftCols<cols>()
P.leftCols(cols)
P.middleCols<cols>(j)
P.middleCols(j, cols)
P.rightCols<cols>()
P.rightCols(cols)
P.topRows<rows>()
P.topRows(rows)
P.middleRows<rows>(i)
P.middleRows(i, rows)
P.bottomRows<rows>()
P.bottomRows(rows)
P.topLeftCorner(rows, cols)
P.topRightCorner(rows, cols)
P.bottomLeftCorner(rows, cols)
P.bottomRightCorner(rows, cols)
P.topLeftCorner<rows,cols>()
P.topRightCorner<rows,cols>()
P.bottomLeftCorner<rows,cols>()
P.bottomRightCorner<rows,cols>()
Eigen 中矩阵元素交换
R.row(i) = P.col(j);
R.col(j1).swap(mat1.col(j2));
Eigen 中矩阵转置
R.adjoint()
R.transpose()
R.diagonal()
x.asDiagonal()
R.transpose().colwise().reverse();
R.conjugate()
Eigen 中矩阵乘积
y = M*x; R = P*Q; R = P*s;
a = b*M; R = P - Q; R = s*P;
a *= M; R = P + Q; R = P/s;
R *= Q; R = s*P;
R += Q; R *= s;
R -= Q; R /= s;
Eigen 中矩阵元素操作
R = P.cwiseProduct(Q);
R = P.array() * s.array();
R = P.cwiseQuotient(Q);
R = P.array() / Q.array();
R = P.array() + s.array();
R = P.array() - s.array();
R.array() += s;
R.array() -= s;
R.array() < Q.array();
R.array() <= Q.array();
R.cwiseInverse();
R.array().inverse();
R.array().sin()
R.array().cos()
R.array().pow(s)
R.array().square()
R.array().cube()
R.cwiseSqrt()
R.array().sqrt()
R.array().exp()
R.array().log()
R.cwiseMax(P)
R.array().max(P.array())
R.cwiseMin(P)
R.array().min(P.array())
R.cwiseAbs()
R.array().abs()
R.cwiseAbs2()
R.array().abs2()
(R.array() < s).select(P,Q);
Eigen 中矩阵化简
int r, c;
R.minCoeff()
R.maxCoeff()
s = R.minCoeff(&r, &c)
s = R.maxCoeff(&r, &c)
R.sum()
R.colwise().sum()
R.rowwise().sum()
R.prod()
R.colwise().prod()
R.rowwise().prod()
R.trace()
R.all()
R.colwise().all()
R.rowwise().all()
R.any()
R.colwise().any()
R.rowwise().any()
Eigen 中矩阵点乘
x.norm()
x.squaredNorm()
x.dot(y)
x.cross(y)
Eigen 中矩阵类型转换
Type conversion
A.cast<double>();
A.cast<float>();
A.cast<int>();
A.real();
A.imag();
Eigen 中求解线性方程组 Ax = b
x = A.ldlt().solve(b));
x = A.llt() .solve(b));
x = A.lu() .solve(b));
x = A.qr() .solve(b));
x = A.svd() .solve(b));
Eigen 中矩阵特征值
A.eigenvalues();
EigenSolver<Matrix3d> eig(A);
eig.eigenvalues();
eig.eigenvectors();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)