UNPKG

662 BJavaScriptView Raw
1// load math.js (using node.js)
2const math = require('../index')
3
4// create a sparse matrix
5console.log('creating a 1000x1000 sparse matrix...')
6const a = math.identity(1000, 1000, 'sparse')
7
8// do operations with a sparse matrix
9console.log('doing some operations on the sparse matrix...')
10const b = math.multiply(a, a)
11const c = math.multiply(b, math.complex(2, 2))
12const d = math.transpose(c)
13const e = math.multiply(d, a)
14console.log('size(e)=', e.size())
15
16// we will not print the output, but doing the same operations
17// with a dense matrix are very slow, try it for yourself.
18console.log('already done')
19console.log('now try this with a dense matrix :)')