Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

#raise(-1) inverts the matrix

  • Loading branch information...
commit f620caafd76a03de47ccb041bde546620eb511a8 1 parent 6902b11
@angusgibbs authored
Showing with 17 additions and 0 deletions.
  1. +5 −0 lib/matrix.js
  2. +12 −0 test/test.js
View
5 lib/matrix.js
@@ -287,6 +287,11 @@
throwError('The power must be an integer');
}
+ // If the power is -1 invert the matrix
+ if (power === -1) {
+ return this.inverse();
+ }
+
// Throw an error if the power is not >= 2
if (power < 2) {
throwError('The power must be greater than or equal to 1');
View
12 test/test.js
@@ -171,6 +171,18 @@ describe('Matrix', function() {
}).to.throwError();
});
+ it('should invert the matrix if the power is -1', function() {
+ expect(new Matrix([
+ [2, 0, -1],
+ [2, 1, 1],
+ [3, 4, 4]
+ ]).raise(-1).toArray()).to.eql([
+ [ 0, .8, -.2],
+ [ 1, -2.2, .8],
+ [-1, 1.6, -.4]
+ ]);
+ });
+
it('should throw an error if the power is less than 2', function() {
expect(function() {
m1.raise(1);
Please sign in to comment.
Something went wrong with that request. Please try again.