MathJS A Math Library For JavaScript
Written by Ian Elliot   
Monday, 06 January 2014

What a language is good at depends a little on its basic syntax and semantics, but a whole lot more on what libraries are easily available. If you don't think of JavaScript as a math language then perhaps you need to meet Math.js.

 

mathjs

 

Math.js is a simple extension to the standard Math object that you should be familiar with. For example 

math.pow(2,3)

returns 2 raised to the power 3. Math.js also has a pow function but it can raise complex numbers, big numbers or matrices to a power. 

One of the most important features of Math.js is that is supports a range of data types and, as far as possible all of its functions work with all of the available data types. You can use standard number, Bignumber i.e. arbitrary precision, complex numbers and matrices. You can also define units for physical calculations.  

For example:

var a = math.complex(2, 3); 
var b = math.complex('4 - 2i'); 

defines complex numbers and you can work with them using

math.add(a,b);

and similar functions.  You can also use the eval method to work out arithmetic expressions involving any of the data types without having to use the special functions. For example:

math.eval('a+b');

does complex addition if a and b are complex.

As well as the basic operators, you also have some more advanced function such as math.inv to find the inverse of a matrix and a small number of probability and stats functions.

It has to be admitted that the range of facilities doesn't put Math.js into same class as Python's NumPy, but it is heading in the right direction.  You can use it in the browser or as a Node.js library and, of course, it has the advantage of working in the same way on the client or server. It is open source and you can alway help extend it.

The big problem with JavaScript and number crunching is speed. It would be interesting to see if Math.js could be optimized by introducing the asm.js data types. This would be a lot of work but the result would be something that worked at close to the speeds achevable by native code.  

 

mathjs

More Information

http://mathjs.org/

Related Articles

Asm.js Gets Faster       

Free Sage Math Cloud - Python And Symbolic Math

GUI For GNU Octave 3.8 

JavaScript Data Structures - Typed Arrays I

JavaScript Data Structures - Typed Arrays II

 

 

To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, FacebookGoogle+ or Linkedin,  or sign up for our weekly newsletter.

 

blog comments powered by Disqus

 

Banner


A Quick Guide To Platform Conversion With Xamarin.Forms
01/07/2014

Xamarin has produced a handy cheat sheet showing how app controls differ between iOS, Android and Windows Phone. It makes a fascinating comparison and you can't help wonder why we can't have a standar [ ... ]



ServiceWorkers Are Coming!
02/07/2014

Mozilla has just announced that it will have ServiceWorker support in Firefox and Firefox OS by the end of September. The only question in your mind right now is - ServiceWorkers?


More News

Last Updated ( Monday, 06 January 2014 )
 
 

   
RSS feed of news items only
I Programmer News
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.