无法使用库 https://github.com/hiddentao/linear-algebra 运行简单示例

Unable to run simple example using library https://github.com/hiddentao/linear-algebra

本文关键字:linear-algebra hiddentao 运行 简单 com github https      更新时间:2023-09-26

我正在尝试使用库:https://github.com/hiddentao/linear-algebra

文档状态使用:

Include dist/linear-algebra.js script into your HTML.
In the browser the library is exposed via the linearAlgebra() function.

但是使用代码:

<script src="linear-algebra.js"></script>
<!-- https://github.com/hiddentao/linear-algebra
 -->
<script>
var m = new linearAlgebra().Matrix([ [1, 2, 3], [4, 5, 6] ]);
console.log( m.rows );     // 2
console.log( m.cols );     // 3
console.log( m.data );     // [ [1, 2, 3], [4, 5, 6] ]
</script>

导致铬错误:

Uncaught TypeError: Cannot read property 'rows' of undefined

我没有以正确的方式使用库,应该只能使用 linearAlgebra() ref ?

任何其他建议js数学库赞赏。

new linearAlgebra().Matrix(...)

被解释为

( new linearAlgebra() ).Matrix(...)

由于JS优先级规则(有关详细信息,请参阅此处)。

将其括在括号中以获得您想要的内容:

new ( linearAlgebra().Matrix )(...)