Math.js: Flexible and powerful JavaScript math library __ Large data

Source: Internet
Author: User
Tags eval

Recently for options to develop some basic technical indicators, the use of some C + + math library, just see the JavaScript math.js Library, here to Math.js do a brief introduction.

One, what is Math.js

Math.js is a mathematical library that is widely used in JavaScript and node.js, featuring flexible expression parsers, support for symbolic computations, built-in numbers of functions and constants, and an integrated solution to handle different data types, such as numbers, large numbers, plural, fractions, units, and matrices.
Math.js can be used in browsers, Node.js, and any JavaScript engines. [Download Address: http://mathjs.org/download.html]

Second, Features

1, support numbers, large numbers, complex numbers, fractions, units, strings, arrays, and matrices.

2, compatible with JavaScript's built-in math library.

3, contains a flexible expression parser

4, symbolic calculation.

5, built-in a large number of functions and constants.

6, no dependencies, running on any JavaScript engine.

7. Can be used as a command line application.

8, easy to expand

9. Open Source


Iii. usage

Math.js supports various Package Manager (EX:NPM & Bower) installations or downloads libraries from the Web site http://mathjs.org/download.html.
Install via NPM:

PM Install MATHJS

Install via Bower:

Bower Install MATHJS

Math.js can be downloaded or linked from CDNJS:

Https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.16.0/math.min.js

Math.js can resemble JavaScript's built-in math library. In addition, math.js can use eval expressions and support linking operations. Here are three ways to use Math.js:

1. Use static functions and constants (like the Math object in JavaScript)

Math.Round (MATH.E, 3);  2.718math.add (2, 3);  5 Math.sqrt (-4);     2i Math.pow ([[1, 2], [3, 1]],2);  [[7, 0], [0, 7]]math.derivative (' x^2 + x ', ' X ');      2 * x + 1math.atan2 (3,-3)/Math.PI; 0.75

2, the string expression to evaluate the operation

Math.eval (' 12/(2.3 + 0.7) ');     4math.eval (' 12.7 cm to inch ');     5 Inchmath.eval (' sin (deg) ^ 2 ');          0.5math.eval (' 9/3 + 2i ');  3 + 2imath.eval (' det ([-1, 2; 3, 1]) '; -7

3, chain-type operation

Math.chain (3). Add (4). Multiply (2). done (); 14

4. Matrix operation

var n = Math.matrix ([[[4,3,2], [6,6,8], [7,4,5]]); Console.log (N.valueof ()); [[4,3,2],[6,6,8],[7,4,5]]

You can use the following code to create a 0-filled matrix:

var z = math.zeros (2,2);   Console.log (Z.valueof ()); [[0, 0], [0, 0]]

Note: Most math.js functions require the valueof () or done () function to actually get the value of the operation, as shown in the above code.

5, Bignumbers

var B = Math.complex (' 4-2i '); b.re = 5;console.log (b.valueof ()); 5-2i

Math.js supports bignumbers with arbitrary precision and is a complex number with real and imaginary parts.

Math.js Document Address: http://mathjs.org/docs/index.html


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.