{"id":8642,"date":"2024-06-01T16:01:01","date_gmt":"2024-06-01T08:01:01","guid":{"rendered":""},"modified":"2024-06-01T16:01:01","modified_gmt":"2024-06-01T08:01:01","slug":"\u77e9\u9635\u7684eigenvector_\u77e9\u9635\u89e3\u6cd5","status":"publish","type":"post","link":"https:\/\/mushiming.com\/8642.html","title":{"rendered":"\u77e9\u9635\u7684eigenvector_\u77e9\u9635\u89e3\u6cd5"},"content":{"rendered":"
\u8f6c\u8f7d\u4e8e:https:\/\/www.cnblogs.com\/houkai\/p\/6348044.html<\/p>\n
\u63d0\u4f9b\u4e00\u4e9b\u6982\u8ff0\u548c\u7ec6\u8282\uff1a\u5173\u4e8e\u77e9\u9635\u3001\u5411\u91cf\u4ee5\u53ca\u6807\u91cf\u7684\u8fd0\u7b97\u3002<\/p>\n
Eigen\u63d0\u4f9b\u4e86matrix\/vector\u7684\u8fd0\u7b97\u64cd\u4f5c\uff0c\u65e2\u5305\u62ec\u91cd\u8f7d\u4e86c++\u7684\u7b97\u672f\u8fd0\u7b97\u7b26+\/-\/*\uff0c\u4e5f\u5f15\u5165\u4e86\u4e00\u4e9b\u7279\u6b8a\u7684\u8fd0\u7b97\u6bd4\u5982\u70b9\u4e58dot\u3001\u53c9\u4e58cross\u7b49\u3002<\/p>\n
\u5bf9\u4e8eMatrix\u7c7b\uff08matrix\u548cvectors\uff09\u8fd9\u4e9b\u64cd\u4f5c\u53ea\u652f\u6301\u7ebf\u6027\u4ee3\u6570\u8fd0\u7b97\uff0c\u6bd4\u5982\uff1amatrix1*matrix2\u8868\u793a\u77e9\u9635\u7684\u4e58\u673a\uff0cvetor+scalar\u662f\u4e0d\u5141\u8bb8\u7684\u3002\u5982\u679c\u4f60\u60f3\u6267\u884c\u975e\u7ebf\u6027\u4ee3\u6570\u64cd\u4f5c\uff0c\u8bf7\u770b\u4e0b\u4e00\u7bc7\uff08\u6682\u65f6\u653e\u4e0b\uff09\u3002<\/p>\n
\u5de6\u53f3\u4e24\u4fa7\u53d8\u91cf\u5177\u6709\u76f8\u540c\u7684\u5c3a\u5bf8\uff08\u884c\u548c\u5217\uff09\uff0c\u5e76\u4e14\u5143\u7d20\u7c7b\u578b\u76f8\u540c\uff08Eigen\u4e0d\u81ea\u52a8\u8f6c\u5316\u7c7b\u578b\uff09\u64cd\u4f5c\u5305\u62ec\uff1a<\/p>\n
#include <iostream>\n#include <Eigen\/Dense>\nusing namespace Eigen;\nint main()\n{\n Matrix2d a;\n a << 1, 2,\n 3, 4;\n MatrixXd b(2,2);\n b << 2, 3,\n 1, 4;\n std::cout << \"a + b =\\n\" << a + b << std::endl;\n std::cout << \"a - b =\\n\" << a - b << std::endl;\n std::cout << \"Doing a += b;\" << std::endl;\n a += b;\n std::cout << \"Now a =\\n\" << a << std::endl;\n Vector3d v(1,2,3);\n Vector3d w(1,0,0);\n std::cout << \"-v + w - v =\\n\" << -v + w - v << std::endl;\n}\n<\/code><\/pre>\n\u8f93\u51fa\uff1a<\/p>\n
a + b =\n3 5\n4 8\na - b =\n-1 -1\n 2 0\nDoing a += b;\nNow a =\n3 5\n4 8\n-v + w - v =\n-1\n-4\n-6\n<\/code><\/pre>\n\u6807\u91cf\u4e58\u6cd5\u548c\u9664\u6cd5<\/h3>\n
\u4e58\/\u9664\u6807\u91cf\u662f\u975e\u5e38\u7b80\u5355\u7684\uff0c\u5982\u4e0b\uff1a<\/p>\n
\n- \u4e8c\u5143\u8fd0\u7b97 * \u5982matrix*scalar<\/li>\n
- \u4e8c\u5143\u8fd0\u7b97 * \u5982scalar*matrix<\/li>\n
- \u4e8c\u5143\u8fd0\u7b97 \/ \u5982matrix\/scalar<\/li>\n
- \u590d\u5408\u8fd0\u7b97 *= \u5982matrix*=scalar<\/li>\n
- \u590d\u5408\u8fd0\u7b97 \/= \u5982matrix\/=scalar<\/li>\n<\/ul>\n
#include <iostream>\n#include <Eigen\/Dense>\nusing namespace Eigen;\nint main()\n{\n Matrix2d a;\n a << 1, 2,\n 3, 4;\n Vector3d v(1,2,3);\n std::cout << \"a * 2.5 =\\n\" << a * 2.5 << std::endl;\n std::cout << \"0.1 * v =\\n\" << 0.1 * v << std::endl;\n std::cout << \"Doing v *= 2;\" << std::endl;\n v *= 2;\n std::cout << \"Now v =\\n\" << v << std::endl;\n}\n<\/code><\/pre>\n\u7ed3\u679c<\/p>\n
a * 2.5 =\n2.5 5\n7.5 10\n0.1 * v =\n0.1\n0.2\n0.3\nDoing v *= 2;\nNow v =\n2\n4\n6\n<\/code><\/pre>\n\u8868\u8fbe\u5f0f\u6a21\u677f<\/h3>\n
\u8fd9\u91cc\u7b80\u5355\u4ecb\u7ecd\uff0c\u5728\u9ad8\u7ea7\u4e3b\u9898\u4e2d\u4f1a\u8be6\u7ec6\u89e3\u91ca\u3002\u5728Eigen\u4e2d\uff0c\u7ebf\u6027\u8fd0\u7b97\u6bd4\u5982+\u4e0d\u4f1a\u5bf9\u53d8\u91cf\u81ea\u8eab\u505a\u4efb\u4f55\u64cd\u4f5c\uff0c\u4f1a\u8fd4\u56de\u4e00\u4e2a\u201c\u8868\u8fbe\u5f0f\u5bf9\u8c61\u201d\u6765\u63cf\u8ff0\u88ab\u6267\u884c\u7684\u8ba1\u7b97\u3002\u5f53\u6574\u4e2a\u8868\u8fbe\u5f0f\u88ab\u8bc4\u4f30\u5b8c\uff08\u4e00\u822c\u662f\u9047\u5230=\u53f7\uff09\uff0c\u5b9e\u9645\u7684\u64cd\u4f5c\u624d\u6267\u884c\u3002<\/p>\n
\u8fd9\u6837\u505a\u4e3b\u8981\u662f\u4e3a\u4e86\u4f18\u5316\uff0c\u6bd4\u5982<\/p>\n
VectorXf a(50), b(50), c(50), d(50);\n...\na = 3*b + 4*c + 5*d;\n<\/code><\/pre>\nEigen\u4f1a\u7f16\u8bd1\u8fd9\u6bb5\u4ee3\u7801\u6700\u7ec8\u904d\u5386\u4e00\u6b21\u5373\u53ef\u8fd0\u7b97\u5b8c\u6210\u3002<\/p>\n
for(int i = 0; i < 50; ++i)\n a[i] = 3*b[i] + 4*c[i] + 5*d[i];\n<\/code><\/pre>\n\u56e0\u6b64\uff0c\u6211\u4eec\u4e0d\u5fc5\u8981\u62c5\u5fc3\u5927\u7684\u7ebf\u6027\u8868\u8fbe\u5f0f\u7684\u8fd0\u7b97\u6548\u7387\u3002<\/p>\n
\u8f6c\u7f6e\u548c\u5171\u8f6d<\/h3>\n
\u8868\u793atranspose\u8f6c\u7f6e<\/p>\n
\u8868\u793aconjugate\u5171\u8f6d<\/p>\n
\u8868\u793aadjoint(\u5171\u8f6d\u8f6c\u7f6e) \u4f34\u968f\u77e9\u9635<\/p>\n
MatrixXcf a = MatrixXcf::Random(2,2);\ncout << \"Here is the matrix a\\n\" << a << endl;\ncout << \"Here is the matrix a^T\\n\" << a.transpose() << endl;\ncout << \"Here is the conjugate of a\\n\" << a.conjugate() << endl;\ncout << \"Here is the matrix a^*\\n\" << a.adjoint() << endl;\n<\/code><\/pre>\n\u8f93\u51fa<\/p>\n
Here is the matrix a\n (-0.211,0.68) (-0.605,0.823)\n (0.597,0.566) (0.536,-0.33)\nHere is the matrix a^T\n (-0.211,0.68) (0.597,0.566)\n(-0.605,0.823) (0.536,-0.33)\nHere is the conjugate of a\n (-0.211,-0.68) (-0.605,-0.823)\n (0.597,-0.566) (0.536,0.33)\nHere is the matrix a^*\n (-0.211,-0.68) (0.597,-0.566)\n(-0.605,-0.823) (0.536,0.33)\n<\/code><\/pre>\n\u5bf9\u4e8e\u5b9e\u6570\u77e9\u9635\uff0cconjugate\u4e0d\u6267\u884c\u4efb\u4f55\u64cd\u4f5c\uff0cadjoint\u7b49\u4ef7\u4e8etranspose\u3002<\/p>\n
transpose\u548cadjoint\u4f1a\u7b80\u5355\u7684\u8fd4\u56de\u4e00\u4e2a\u4ee3\u7406\u5bf9\u8c61\u5e76\u4e0d\u5bf9\u672c\u7701\u505a\u8f6c\u7f6e\u3002\u5982\u679c\u6267\u884c b=a.transpose()<\/code> \uff0ca\u4e0d\u53d8\uff0c\u8f6c\u7f6e\u7ed3\u679c\u88ab\u8d4b\u503c\u7ed9b\u3002\u5982\u679c\u6267\u884c a=a.transpose()<\/code> Eigen\u5728\u8f6c\u7f6e\u7ed3\u675f\u4e4b\u524d\u7ed3\u679c\u4f1a\u5f00\u59cb\u5199\u5165a\uff0c\u6240\u4ee5a\u7684\u6700\u7ec8\u7ed3\u679c\u4e0d\u4e00\u5b9a\u7b49\u4e8ea\u7684\u8f6c\u7f6e\u3002<\/p>\nMatrix2i a; a << 1, 2, 3, 4;\ncout << \"Here is the matrix a:\\n\" << a << endl;\na = a.transpose(); \/\/ !!! do NOT do this !!!\ncout << \"and the result of the aliasing effect:\\n\" << a << endl;\n\nHere is the matrix a:\n1 2\n3 4\nand the result of the aliasing effect:\n1 2\n2 4\n<\/code><\/pre>\n\u8fd9\u88ab\u79f0\u4e3a\u201c\u522b\u540d\u95ee\u9898\u201d\u3002\u5728debug\u6a21\u5f0f\uff0c\u5f53assertions\u6253\u5f00\u7684\u60c5\u51b5\u52a0\uff0c\u8fd9\u79cd\u5e38\u89c1\u9677\u9631\u53ef\u4ee5\u88ab\u81ea\u52a8\u68c0\u6d4b\u5230\u3002<\/p>\n
\u5bf9 a=a.transpose()<\/code> \u8fd9\u79cd\u64cd\u4f5c\uff0c\u53ef\u4ee5\u6267\u884cin-palce\u8f6c\u7f6e\u3002\u7c7b\u4f3c\u8fd8\u6709adjointInPlace\u3002<\/p>\nMatrixXf a(2,3); a << 1, 2, 3, 4, 5, 6;\ncout << \"Here is the initial matrix a:\\n\" << a << endl;\na.transposeInPlace();\ncout << \"and after being transposed:\\n\" << a << endl;\n\nHere is the initial matrix a:\n1 2 3\n4 5 6\nand after being transposed:\n1 4\n2 5\n3 6\n<\/code><\/pre>\n\u77e9\u9635-\u77e9\u9635\u7684\u4e58\u6cd5\u548c\u77e9\u9635-\u5411\u91cf\u7684\u4e58\u6cd5<\/h3>\n
\u5411\u91cf\u4e5f\u662f\u4e00\u79cd\u77e9\u9635\uff0c\u5b9e\u8d28\u90fd\u662f\u77e9\u9635-\u77e9\u9635\u7684\u4e58\u6cd5\u3002<\/p>\n
\n- \u4e8c\u5143\u8fd0\u7b97 *\u5982a*b<\/li>\n
- \u590d\u5408\u8fd0\u7b97 *=\u5982a*=b<\/li>\n<\/ul>\n
#include <iostream>\n#include <Eigen\/Dense>\nusing namespace Eigen;\nint main()\n{\n Matrix2d mat;\n mat << 1, 2,\n 3, 4;\n Vector2d u(-1,1), v(2,0);\n std::cout << \"Here is mat*mat:\\n\" << mat*mat << std::endl;\n std::cout << \"Here is mat*u:\\n\" << mat*u << std::endl;\n std::cout << \"Here is u^T*mat:\\n\" << u.transpose()*mat << std::endl;\n std::cout << \"Here is u^T*v:\\n\" << u.transpose()*v << std::endl;\n std::cout << \"Here is u*v^T:\\n\" << u*v.transpose() << std::endl;\n std::cout << \"Let's multiply mat by itself\" << std::endl;\n mat = mat*mat;\n std::cout << \"Now mat is mat:\\n\" << mat << std::endl;\n}\n<\/code><\/pre>\n\u8f93\u51fa<\/p>\n
Here is mat*mat:\n 7 10\n15 22\nHere is mat*u:\n1\n1\nHere is u^T*mat:\n2 2\nHere is u^T*v:\n-2\nHere is u*v^T:\n-2 -0\n 2 0\nLet's multiply mat by itself\nNow mat is mat:\n 7 10\n15 22\n<\/code><\/pre>\nm=m*m<\/code>\u5e76\u4e0d\u4f1a\u5bfc\u81f4\u522b\u540d\u95ee\u9898\uff0cEigen\u5728\u8fd9\u91cc\u505a\u4e86\u7279\u6b8a\u5904\u7406\uff0c\u5f15\u5165\u4e86\u4e34\u65f6\u53d8\u91cf\u3002\u5b9e\u8d28\u5c06\u7f16\u8bd1\u4e3a\uff1a<\/p>\ntmp = m*m\nm = tmp\n<\/code><\/pre>\n\u5982\u679c\u4f60\u786e\u5b9a\u77e9\u9635\u4e58\u6cd5\u662f\u5b89\u5168\u7684\uff08\u5e76\u6ca1\u6709\u522b\u540d\u95ee\u9898\uff09\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528noalias()\u51fd\u6570\u6765\u907f\u514d\u4e34\u65f6\u53d8\u91cf c.noalias() += a*b<\/code> \u3002<\/p>\n\u70b9\u8fd0\u7b97\u548c\u53c9\u8fd0\u7b97<\/h3>\n
dot()\u6267\u884c\u70b9\u79ef\uff0ccross()\u6267\u884c\u53c9\u79ef\uff0c\u70b9\u8fd0\u7b97\u5f97\u52301*1\u7684\u77e9\u9635\u3002\u5f53\u7136\uff0c\u70b9\u8fd0\u7b97\u4e5f\u53ef\u4ee5\u7528u.adjoint()*v\u6765\u4ee3\u66ff\u3002<\/p>\n
#include <iostream>\n#include <Eigen\/Dense>\nusing namespace Eigen;\nusing namespace std;\nint main()\n{\n Vector3d v(1,2,3);\n Vector3d w(0,1,2);\n cout << \"Dot product: \" << v.dot(w) << endl;\n double dp = v.adjoint()*w; \/\/ automatic conversion of the inner product to a scalar\n cout << \"Dot product via a matrix product: \" << dp << endl;\n cout << \"Cross product:\\n\" << v.cross(w) << endl;\n}\n<\/code><\/pre>\n\u8f93\u51fa<\/p>\n
Dot product: 8\nDot product via a matrix product: 8\nCross product:\n 1\n-2\n 1\n<\/code><\/pre>\n\u6ce8\u610f\uff1a\u70b9\u79ef\u53ea\u5bf9\u4e09\u7ef4vector\u6709\u6548\u3002\u5bf9\u4e8e\u590d\u6570\uff0cEigen\u7684\u70b9\u79ef\u662f\u7b2c\u4e00\u4e2a\u53d8\u91cf\u5171\u8f6d\u548c\u7b2c\u4e8c\u4e2a\u53d8\u91cf\u7684\u7ebf\u6027\u79ef\u3002<\/p>\n
\u57fa\u7840\u7684\u5f52\u7ea6\u64cd\u4f5c<\/h3>\n
Eigen\u63d0\u4f9b\u4e86\u800c\u4e00\u4e9b\u5f52\u7ea6\u51fd\u6570\uff1asum()\u3001prod()\u3001maxCoeff()\u548cminCoeff()\uff0c\u4ed6\u4eec\u5bf9\u6240\u6709\u5143\u7d20\u8fdb\u884c\u64cd\u4f5c\u3002<\/p>\n
#include <iostream>\n#include <Eigen\/Dense>\nusing namespace std;\nint main()\n{\n Eigen::Matrix2d mat;\n mat << 1, 2,\n 3, 4;\n cout << \"Here is mat.sum(): \" << mat.sum() << endl;\n cout << \"Here is mat.prod(): \" << mat.prod() << endl;\n cout << \"Here is mat.mean(): \" << mat.mean() << endl;\n cout << \"Here is mat.minCoeff(): \" << mat.minCoeff() << endl;\n cout << \"Here is mat.maxCoeff(): \" << mat.maxCoeff() << endl;\n cout << \"Here is mat.trace(): \" << mat.trace() << endl;\n}\n<\/code><\/pre>\n\u8f93\u51fa<\/p>\n
Here is mat.sum(): 10\nHere is mat.prod(): 24\nHere is mat.mean(): 2.5\nHere is mat.minCoeff(): 1\nHere is mat.maxCoeff(): 4\nHere is mat.trace(): 5\n<\/code><\/pre>\ntrace\u8868\u793a\u77e9\u9635\u7684\u8ff9\uff0c\u5bf9\u89d2\u5143\u7d20\u7684\u548c\u7b49\u4ef7\u4e8e a.diagonal().sum()<\/code> \u3002<\/p>\nminCoeff\u548cmaxCoeff\u51fd\u6570\u4e5f\u53ef\u4ee5\u8fd4\u56de\u7ed3\u679c\u5143\u7d20\u7684\u4f4d\u7f6e\u4fe1\u606f\u3002<\/p>\n
Matrix3f m = Matrix3f::Random();\n std::ptrdiff_t i, j;\n float minOfM = m.minCoeff(&i,&j);\n cout << \"Here is the matrix m:\\n\" << m << endl;\n cout << \"Its minimum coefficient (\" << minOfM \n << \") is at position (\" << i << \",\" << j << \")\\n\\n\";\n RowVector4i v = RowVector4i::Random();\n int maxOfV = v.maxCoeff(&i);\n cout << \"Here is the vector v: \" << v << endl;\n cout << \"Its maximum coefficient (\" << maxOfV \n << \") is at position \" << i << endl;\n<\/code><\/pre>\n\u8f93\u51fa<\/p>\n
Here is the matrix m:\n 0.68 0.597 -0.33\n-0.211 0.823 0.536\n 0.566 -0.605 -0.444\nIts minimum coefficient (-0.605) is at position (2,1)\n\nHere is the vector v: 1 0 3 -3\nIts maximum coefficient (3) is at position 2\n<\/code><\/pre>\n\u64cd\u4f5c\u7684\u6709\u6548\u6027<\/h3>\n
Eigen\u4f1a\u68c0\u6d4b\u6267\u884c\u64cd\u4f5c\u7684\u6709\u6548\u6027\uff0c\u5728\u7f16\u8bd1\u9636\u6bb5Eigen\u4f1a\u68c0\u6d4b\u5b83\u4eec\uff0c\u9519\u8bef\u4fe1\u606f\u662f\u7e41\u5197\u7684\uff0c\u4f46\u9519\u8bef\u4fe1\u606f\u4f1a\u5927\u5199\u5b57\u6bcd\u7a81\u51fa\uff0c\u6bd4\u5982:<\/p>\n
Matrix3f m;\nVector4f v;\nv = m*v; \/\/ Compile-time error: YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES\n<\/code><\/pre>\n\u5f53\u7136\u52a8\u6001\u5c3a\u5bf8\u7684\u9519\u8bef\u8981\u5728\u8fd0\u884c\u65f6\u53d1\u73b0\uff0c\u5982\u679c\u5728debug\u6a21\u5f0f\uff0cassertions\u4f1a\u89e6\u53d1\u540e\uff0c\u7a0b\u5e8f\u5c06\u5d29\u6e83\u3002<\/p>\n
MatrixXf m(3,3);\nVectorXf v(4);\nv = m * v; \/\/ Run-time assertion failure here: \"invalid matrix product\"<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"\u77e9\u9635\u7684eigenvector_\u77e9\u9635\u89e3\u6cd5\u8f6c\u8f7d\u4e8e:https:\/\/www.cnblogs.com\/houkai\/p\/6348044.html\u77e9\u9635\u548c\u5411\u91cf\u7684\u8fd0\u7b97\u63d0\u4f9b\u4e00\u4e9b\u6982\u8ff0\u548c\u7ec6\u8282\uff1a\u5173...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8642"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=8642"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8642\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=8642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=8642"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=8642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}