- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 Armadillo 和 C++,我试图找到矩阵的逆矩阵,但是,逆矩阵只返回矩阵本身。
在我看来,没有任何计算。此外,不会引发任何错误。
我正在使用以下 header :
#include <armadillo>
using namespace std;
using namespace arma;
我已经使用 Armadillo 几天了,并运行了几个正常工作的矩阵操作。
输入:
mat A = randu<mat>(5,5);
A.print("A: ");
mat B = inv(A);
B.print("inv(A): ");
输出:
A:
0.0013 0.1741 0.9885 0.1662 0.8760
0.1933 0.7105 0.1191 0.4508 0.9559
0.5850 0.3040 0.0089 0.0571 0.5393
0.3503 0.0914 0.5317 0.7833 0.4621
0.8228 0.1473 0.6018 0.5199 0.8622
inv(A):
0.0013 0.1741 0.9885 0.1662 0.8760
0.1933 0.7105 0.1191 0.4508 0.9559
0.5850 0.3040 0.0089 0.0571 0.5393
0.3503 0.0914 0.5317 0.7833 0.4621
0.8228 0.1473 0.6018 0.5199 0.8622
Process finished with exit code 0
问题:
为什么 inv(ofAMatrix) 不工作,有什么提示或想法吗?谢谢!
最佳答案
这与带有 Intel (R) MKL 的 Armadillo 7.900.1 一起工作得很好后端和 Clang 5.0。
除非绝对必要,否则永远不要对矩阵求逆。此外,您还必须确保逆函数确实存在,否则算法将愉快地输出垃圾。如果您想计算 A 的倒数以找到 x,如
x = A-1 b
求解线性系统比较好
A x = b
相反。这些求解器速度更快,收敛性更好。
#include <armadillo>
int main()
{
arma::mat A = { { 0.0013 , 0.1741 , 0.9885 , 0.1662 , 0.8760 } ,
{ 0.1933 , 0.7105 , 0.1191 , 0.4508 , 0.9559 } ,
{ 0.5850 , 0.3040 , 0.0089 , 0.0571 , 0.5393 } ,
{ 0.3503 , 0.0914 , 0.5317 , 0.7833 , 0.4621 } ,
{ 0.8228 , 0.1473 , 0.6018 , 0.5199 , 0.8622 } };
A.print("A: ");
arma::mat B = arma::inv(A);
B.print("inv(A): ");
arma::mat I = A*B;
I.print("I: ");
}
输出:
A:
0.0013 0.1741 0.9885 0.1662 0.8760
0.1933 0.7105 0.1191 0.4508 0.9559
0.5850 0.3040 0.0089 0.0571 0.5393
0.3503 0.0914 0.5317 0.7833 0.4621
0.8228 0.1473 0.6018 0.5199 0.8622
inv(A):
0.4736 -1.7906 4.4377 2.2515 -2.4784
2.9108 -3.1697 12.1159 7.7356 -11.1675
2.5212 -2.8557 6.8074 4.7142 -6.1801
-1.0317 0.9400 -2.3230 0.2413 1.3297
-2.0869 3.6766 -9.6555 -6.9062 8.9447
I:
1.0000e+00 1.1340e-16 -1.8134e-15 -6.4918e-16 -4.8899e-17
7.6334e-17 1.0000e+00 -9.1810e-16 -9.4668e-16 8.7907e-16
2.5424e-16 -4.3981e-16 1.0000e+00 9.2981e-16 -2.0864e-15
9.3036e-17 -2.6745e-17 7.5137e-16 1.0000e+00 -8.1372e-16
4.3422e-16 -4.2293e-16 1.1321e-15 1.0687e-15 1.0000e+00
关于c++ - Armadillo C++ 找不到矩阵求逆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44510612/
例如,我有一个父类Author: class Author { String name static hasMany = [ fiction: Book,
代码如下: dojo.query(subNav.navClass).forEach(function(node, index, arr){ if(dojo.style(node, 'd
我有一个带有 Id 和姓名的学生表和一个带有 Id 和 friend Id 的 Friends 表。我想加入这两个表并找到学生的 friend 。 例如,Ashley 的 friend 是 Saman
我通过互联网浏览,但仍未找到问题的答案。应该很容易: class Parent { String name Child child } 当我有一个 child 对象时,如何获得它的 paren
我正在尝试创建一个以 Firebase 作为我的后端的社交应用。现在我正面临如何(在哪里?)找到 friend 功能的问题。 我有每个用户的邮件地址。 我可以访问用户的电话也预订。 在传统的后端中,我
我主要想澄清以下几点: 1。有人告诉我,在 iOS 5 及以下版本中,如果您使用 Game Center 设置多人游戏,则“查找 Facebook 好友”(如与好友争夺战)的功能不是内置的,因此您需要
关于redis docker镜像ENTRYPOINT脚本 docker-entrypoint.sh : #!/bin/sh set -e # first arg is `-f` or `--some-
我是一名优秀的程序员,十分优秀!