# Numeric JavaScript

You should install `node` and `npm`.

For the jupyter kernel, I used this: https://www.npmjs.com/package/ijavascript

There's also this: https://github.com/notablemind/jupyter-nodejs

I bet there are others.

## Numeric JS

Following along from http://www.numericjs.com/workshop.php

I am using the minified JS file in this repo.

``````

In [1]:

var n = require('./numeric-1.2.6.min.js');

``````
``````

Out[1]:

undefined

``````
``````

In [2]:

// Linear algebra example. We start with a matrix.
var A = [[1,2,3],
[4,5,6],
[7,3,9]];
A

``````
``````

Out[2]:

[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 3, 9 ] ]

``````
``````

In [3]:

// Let's also make a vector.
var x = [3,1,2];
x

``````
``````

Out[3]:

[ 3, 1, 2 ]

``````
``````

In [4]:

// Matrix-vector product.
var b = n.dot(A, x);
b

``````
``````

Out[4]:

[ 11, 29, 42 ]

``````
``````

In [5]:

// Matrix inverse.
var Ainv = n.inv(A);
Ainv

``````
``````

Out[5]:

[ [ -0.9, 0.30000000000000004, 0.09999999999999998 ],
[ -0.1999999999999999,
0.39999999999999997,
-0.19999999999999998 ],
[ 0.7666666666666666, -0.3666666666666667, 0.09999999999999998 ] ]

``````
``````

In [6]:

// Let's check it:
n.dot(Ainv,b);

``````
``````

Out[6]:

[ 3, 1.0000000000000018, 1.9999999999999982 ]

``````
``````

In [7]:

// Determinant
numeric.det(A);

``````
``````

Out[7]:

-29.999999999999996

``````
``````

In [8]:

// Eigenvalues.
ev = numeric.eig(A)

``````
``````

Out[8]:

{ lambda:
{ x: [ 13.98887031606829, -1.0436794353124923, 2.054809119244198 ],
y: undefined },
E: { x: [ [Object], [Object], [Object] ], y: undefined } }

``````

## Hidden Tao

Need to try this too: https://github.com/hiddentao/linear-algebra

``````

In [ ]:

``````