功能强大的JavaScript数学工具包: Math.js

jopen 11年前

Math.js是一个JavaScript包用于执行数学相关的函数。拥有非常多的运算功能和灵活的表达式解析器。功能强大且易于使用。

特性:

  • 支持numbers, complex numbers, units, strings, arrays, 和 matrices。
  • 包含非常多的内置函数和常数。
  • 包含一个灵活的表达式解析器。
  • 兼容JavaScript内置的数学库。
  • 没有依赖关系。运行在任何JavaScript引擎中。
  • Easily extensible.



// load math.js  var math = require('mathjs');    // methods and constants  math.round(math.e, 3);            // 2.718  math.atan2(3, -3) / math.pi;      // 0.75  math.log(1000, 10);               // 3    // complex numbers  var c = math.complex(3, -4);      // 3 - 4i  math.add(c, 2);                   // 5 - 2i  math.sqrt(-4);                    // 2i    // parse expressions. use units  var parser = math.parser();  parser.eval('1.2 / (2.3 + 0.7)'); // 0.4  parser.eval('a = 5.08 cm');  parser.eval('a in inch');         // 2 inch  parser.eval('sin(45 deg) ^ 2');   // 0.5    // arrays and matrices  var a = [[1, 2], [3, 4]];  var b = math.matrix([[5, 6]]);  b.set([2, 1], 7);  b.set([2, 2], 8);  var c = math.multiply(a, b);  math.format(a); // [[1, 2], [3, 4]]  math.format(b); // [[5, 6], [7, 8]]  math.format(c); // [[19, 22], [43, 50]]  var d = parser.eval('[-1, 2; 3, 1]');  math.det(d);    // -7

项目主页:http://www.open-open.com/lib/view/home/1365476071671