Skip to content

Commit

Permalink
added method for checking linear dependence
Browse files Browse the repository at this point in the history
  • Loading branch information
ashnur committed Sep 14, 2013
1 parent 58a3f68 commit 0993e6d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,15 @@ void function(root){

}

function invert(matrix){
function spanning(matrix){
var size = Math.max(matrix.length, matrix[0].length)
, target = fully_reduce(matrix.filter(function(row, i){ return i < size })
.map(function(row){
return row.filter(function(col, i){
return i < size
})
}))
return is_identity(target[0])
}

function vatrix(arr){ return arr.map(m) }
Expand Down Expand Up @@ -268,6 +276,7 @@ void function(root){
vatrix.rowReduce = fully_reduce
vatrix.mrr = fully_reduce

vatrix.isSpanning = spanning
vatrix.drawMatrix = draw_matrix
vatrix.isLowerTriangular = is_lower_triangular
vatrix.isUpperTriangular = is_upper_triangular
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vatrix",
"description": "matrix tools",
"version": "0.0.3",
"version": "0.0.4",
"scripts": {
"test": "mocha",
"prepublish": "npm test"
Expand Down
8 changes: 8 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,15 @@ describe('vectors', function(){
,[r(35421),r(-182516),r(211537)]
]), r(154363999) ))
test([[32, 551, 23], [111, 391, 12], [122, 123, 2], [332, 13, 832]])
test([[2, 2, 2, 2], [2, -2, 2, -2]])
})

})

describe('spanning set', function(){
it('returns true if the matrix is spanning', function(){
expect(vatrix.isSpanning(vatrix([[1,2,-1],[2,0,4],[-1,1,3]]))).to.be(true)
expect(vatrix.isSpanning(vatrix([[1,2,-1,3],[2,-1,8,1],[-3,4,17,1]]))).to.be(false)
})
})
})

0 comments on commit 0993e6d

Please sign in to comment.