我想反转矩阵 a 但它不起作用。我需要帮助。
var a = math.inv([[1,2],[3,4]])
console.log(a)
最佳答案
Math
不包含inv
方法。因此你不能调用它。
但是,您可以像 here 那样定义自己的矩阵求逆方法。 ,或者您可以使用 numeric JavaScript library并用以下方式调用它:
A = [[1,2,3], [4,5,6], [7,3,9]]; Ainv = numeric.inv(A);
or use the math.js
library and call it with:
math.inv([[1,2],[3,4]])
Notice that you need a surrounding the list of lists with square brackets (here written in boldface).
In that case, a minimal working example would look like:
<html>
<head>
<script language="JavaScript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.2.1/math.js"></script>
</head>
<body>
<p id="result">loading result...</p>
<script>
var inverted = math.inv([[1,2],[3,4]]);
document.getElementById("result").textContent = JSON.stringify(inverted);
</script>
</body>
</html>
关于javascript - 如何在 JavaScript 中反转矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38000569/