看起来太基础的工作了。然而,我做不到。
我添加math.js
到我的 HTML 代码
<script src="js/math.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
我在 Firefox 控制台中定义了一个矩阵:
var M = math.matrix([[1,0,0,4],[0,1,0,2],[0,5,1,9],[11,2,3,1]]);
Run Code Online (Sandbox Code Playgroud)
到目前为止一切都很好。
M
Object { _data: Array[4], _size: Array[2], _datatype: undefined }
Run Code Online (Sandbox Code Playgroud)
现在,我想访问矩阵的单个元素:
M.index(1,2)
Run Code Online (Sandbox Code Playgroud)
我得到一个错误
类型错误:M.index 不是函数
我正在尝试使用math.js(http://mathjs.org/docs/reference/functions/inv.html),但看不到如何将其包含在HTML文件中。
我读到您可以通过将其添加到文件中来包括它:
var math = require('mathjs');
Run Code Online (Sandbox Code Playgroud)
但这对我没有用
我意识到这听起来像是一个非常愚蠢的问题,但是我试图自己弄清楚这个问题,但没有成功。
要回答我的问题,只需显示一个成功使用math.js的完整HTML文件(不仅仅是其中的一部分代码)
谢谢
我尝试了亚历山大·奥玛拉的建议,得到了:
/** * Math.js can easily be extended with functions and variables using the * `import` function. The function `import` accepts a module name or an object * containing functions and variables. */ // load math.js (using node.js) var math = require('../index'); /** * Define new functions and variables */ math.import({ myConstant: 42, hello: function (name) { return 'hello, ' + name + '!'; } }); // defined …
Run Code Online (Sandbox Code Playgroud)