我在 MATLAB 中有以下代码,在尝试计算lamb我包含的代码以提供一些上下文之前,它会执行 LU 分解。
P=[1,2,3;4,5,6;7,8,9];
U=[0;1;2];
[F,J]=lu(P);
Jlamda=F\U;
lamb=J\Jlamda;
Run Code Online (Sandbox Code Playgroud)
F 是:
P=[1,2,3;4,5,6;7,8,9];
U=[0;1;2];
[F,J]=lu(P);
Jlamda=F\U;
lamb=J\Jlamda;
Run Code Online (Sandbox Code Playgroud)
U 是:
0.142857142857143 1 0
0.571428571428571 0.500000000000000 1
1 0 0
Run Code Online (Sandbox Code Playgroud)
当我尝试使用以下代码在 Eigen 中复制此内容时:
MatrixXd P(3, 3);
P << 1, 2, 3, 4, 5, 6, 7, 8, 9;
MatrixXd U(3, 1);
U << 0, 1, 2;
PartialPivLU<MatrixXd> lu = PartialPivLU<MatrixXd>(P);
MatrixXd J = lu.matrixLU().triangularView<UpLoType::Upper>();
MatrixXd F = lu.matrixLU().triangularView<UpLoType::UnitLower>();
MatrixXd Jlamda = F.lu().solve(U);
MatrixXd l = J.lu().solve(Jlamda);
cout << F << endl; …Run Code Online (Sandbox Code Playgroud)