Permalink
Browse files

added Real General Linear Group

  • Loading branch information...
fibo committed Jan 13, 2013
1 parent b5be06a commit 7e1fac2fa59519ea9e0de3a50bb2d88140370351
View
@@ -53,12 +53,14 @@ This is a 60 seconds tutorial to get your hands dirty with `algebra`.
var algebra = require('algebra');
- var MnR = algebra.Real.MatrixRing;
- var M2R = new MnR(2);
+ // GLnR is the Real General Linear Group of invertible matrices of order n.
+ var GLnR = algebra.Real.GeneralLinearGroup;
- var m1 = new M2R.Matrix(1, 2, 3, 4);
+ // Create a 2x2 invertible matrix.
+ var GL2R = new GLnR(2);
+
+ var m1 = new GL2R.Matrix(1, 2, 3, 4);
- // coming soon :P
# Description
@@ -4,7 +4,6 @@
var albegra = require('algebra');
var GLRn = algebra.Real.GeneralLinearGroup;
-//var GLRn = algebra.Real.GeneralLinearGroup;
var GLR2 = new GLRn(2);
View
@@ -1,7 +0,0 @@
-
-var algebra = require('algebra');
-
-var MnR = algebra.Real.MatrixRing;
-
-var M2R = new MnR(2);
-
View
@@ -1,32 +0,0 @@
-
-var algebra = require('../index.js');
-
-var GLn = algebra.Real.GeneralLinearGroup;
-var Matrix = algebra.Matrix;
-var RealField = algebra.Real.Field;
-
-var GL2 = new GLn(2);
-var GL3 = new GLn(3);
-
-var matrix2 = new GL2.Matrix(0,1,-1,0);
-console.log(matrix2.toString());
-
-matrix2.tr();
-console.log(matrix2.toString());
-
-var matrix3 = new GL3.Matrix(0,1,1,1,0,-1,0,-1,0);
-console.log(matrix3.toString());
-
-/*
-var R = new RealField();
-var matrix2x3 = new Matrix({
- elements: [0, 1, 2, 3, 4, 5],
- field: R,
- numRows: 2,
- numCols: 3
-});
-console.log(matrix2x3.toString());
-matrix2x3.tr();
-console.log(matrix2x3.toString());
-*/
-
View
@@ -1,20 +1,18 @@
exports.Field = require('./lib/Field.js');
-exports.Matrix = require('./lib/Matrix.js');
-exports.MatrixRing = require('./lib/MatrixRing.js');
-exports.SquareMatrix = require('./lib/SquareMatrix.js');
exports.Group = require('./lib/Group.js');
exports.Vector = require('./lib/Vector.js');
exports.VectorSpace = require('./lib/VectorSpace.js');
var Real = {};
-Real.Element = require('./lib/Real/Element.js');
-Real.Field = require('./lib/Real/Field.js');
-Real.Vector = require('./lib/Real/Vector.js');
-Real.VectorSpace = require('./lib/Real/VectorSpace.js');
-Real.MatrixRing = require('./lib/Real/MatrixRing.js');
+Real.Element = require('./lib/Real/Element.js');
+Real.Field = require('./lib/Real/Field.js');
+Real.GeneralLinearGroup = require('./lib/Real/GeneralLinearGroup.js');
+Real.InvertibleMatrix = require('./lib/Real/InvertibleMatrix.js');
+Real.Vector = require('./lib/Real/Vector.js');
+Real.VectorSpace = require('./lib/Real/VectorSpace.js');
exports.Real = Real;
@@ -24,7 +22,6 @@ Complex.Element = require('./lib/Complex/Element.js');
Complex.Field = require('./lib/Complex/Field.js');
//Complex.Vector = require('./lib/Complex/Vector.js');
//Complex.VectorSpace = require('./lib/Complex/VectorSpace.js');
-//Complex.MatrixRing = require('./lib/Complex/MatrixRing.js');
exports.Complex = Complex;
View
@@ -1,7 +1,7 @@
-var MnR = require('../Real/MatrixRing.js');
+var GLnR = require('../Real/GeneralLinearGroup.js');
-var M2R = new MnR(2);
+var GL2R = new GLnR(2);
var ComplexElement = function (a, b) {
var self = this;
@@ -145,7 +145,8 @@ ComplexElement.prototype.toMatrix = function () {
var im = this.im();
var re = this.re();
- return new M2R.Matrix(re, -im, im, re);
+ // TODO if is zero return new M2R.Matrix(re, -im, im, re);
+ return new GL2R.Matrix(re, -im, im, re);
};
ComplexElement.prototype.toString = function () {
View
@@ -1,91 +0,0 @@
-function Matrix(arg) {
- var self = this;
-
- var field = arg.field;
- this.getField = function () { return field; };
-
- var numRows = arg.numRows;
- this.getNumRows = function () { return numRows; };
-
- var numCols = arg.numCols;
- this.getNumCols = function () { return numCols; };
- //console.log(numCols);
-
- var elements = arg.elements;
- this.elems = this.getElements = function () { return elements; };
-
- var index = function(i ,j) {
- return i * numCols + j;
- };
-
- this.ij = function (i, j) {
- return elements[index(i, j)];
- };
-
- this.row = function (rowIndex) {
- var row = [];
- for (var j = 0; j < numCols; j++) {
- var element = self.ij(rowIndex, j);
- row.push(element);
- }
- return row;
- };
-
- this.col = function (colIndex) {
- var col = [];
- for (var i = 0; i < numRows; i++) {
- var element = self.ij(i, colIndex);
- col.push(element);
- }
- return col;
- };
-
- this.toString = function () {
- var str = '';
- for (var i = 0; i < numRows; i++ ) {
- str += '|';
- for (var j = 0; j < numCols; j++ ) {
- str += ' ' + self.ij(i, j) + ' ';
- }
- str += '|\n';
- }
- return str;
- };
-
- this.transpose = this.tr = function () {
- var swap;
-
- for(var i = 0; i < numRows; i++) {
- for(var j = 0; j < numCols; j++) {
- if ( i != j ) {
- var origIndex = index(i, j);
- var newIndex = index(j, i);
-
- swap = elements[origIndex];
- elements[origIndex] = elements[newIndex];
- elements[newIndex] = swap;
- }
- }
- }
-
- swap = numRows;
- numCols = numRows;
- numRows = swap;
-
- return self;
- };
-};
-
-Matrix.prototype = {
- clone: function () {
- return new Matrix({
- field: this.getField(),
- numCols: this.getNumCols(),
- numRows: this.getNumRows(),
- elements: this.getElements()
- });
- }
-};
-
-module.exports = Matrix;
-
View
@@ -1,57 +0,0 @@
-
-var SquareMatrix = require('./SquareMatrix.js');
-
-function MatrixRing(arg) {
- var self = this;
-
- var _field = arg.field;
- this.getField = function () { return _field; };
-
- var _order = arg.order;
- this.getOrder = function () { return _order; };
-
- var zeroElement = _field.getZero();
- var oneElement = _field.getOne();
-
- self.getOne = function () {
- var arg = {};
- arg.field = _field;
- arg.order = _order;
-
- var elements = [];
- for (var i = 0; i < _order; i++) {
- for (var j = 0; j < _order; j++) {
- if (i == j) {
- elements.push(oneElement.clone());
- }
- else {
- elements.push(zeroElement.clone());
- }
- }
- }
- arg.elements = elements;
-
- var one = new SquareMatrix(arg);
-
- return one;
- };
-
- self.getZero = function () {
- var arg = {};
- arg.field = _field;
- arg.order = _order;
-
- var elements = [];
- for (var i = 0; i < _order * _order; i++) {
- elements.push(zeroElement.clone());
- }
- arg.elements = elements;
-
- var zero = new SquareMatrix(arg);
-
- return zero;
- };
-}
-
-module.exports = MatrixRing;
-
@@ -0,0 +1,21 @@
+
+var RealInvertibleMatrix = require('./InvertibleMatrix.js');
+
+function GeneralLinearGroup(order) {
+ var self = this;
+
+ var _order = order;
+
+ self.Matrix = function () {
+ var arg = {};
+
+ arg.order = _order;
+
+ RealInvertibleMatrix.call(this, arg);
+ };
+
+ // TODO self.Id = self.Matrix;
+};
+
+module.exports = GeneralLinearGroup;
+
@@ -0,0 +1,22 @@
+
+function RealInvertibleMatrix(arg) {
+ var self = this;
+
+ var _order = arg.order;
+
+/* TODO
+ // Matrix defaults to big Id.
+ for (var i = 0; i < o; i++) {
+ for (var j = 0; j < o; j++) {
+ var _default = 0;
+ if (i == j) _default = 1;
+ var num = arguments[i*o+j] || _default;
+ var element = new Real(num);
+ arg.elements.push(element);
+ }
+ }
+ */
+};
+
+module.exports = RealInvertibleMatrix;
+
View
@@ -1,46 +0,0 @@
-
-var util = require('util');
-
-var MatrixRing = require('../MatrixRing.js');
-var RealField = require('./Field.js');
-var Real = require('./Element.js');
-var SquareMatrix = require('../Matrix.js');
-
-var R = new RealField();
-
-var RealMatrixRing = function (order) {
- var self = this;
-
- var arg = {};
- arg.order = order;
- arg.field = R;
-
- MatrixRing.call(self, arg);
-
- self.Matrix = function () {
- var arg = {};
- arg.elements = [];
- arg.field = self.getField();
- var o = arg.order = self.getOrder();
-
- // Matrix defaults to big Id.
- for (var i = 0; i < o; i++) {
- for (var j = 0; j < o; j++) {
- var _default = 0;
- if (i == j) _default = 1;
- var num = arguments[i*o+j] || _default;
- var element = new Real(num);
- arg.elements.push(element);
- }
- }
-
- SquareMatrix.call(this, arg);
- };
-
- self.Id = self.Matrix;
-};
-
-util.inherits(RealMatrixRing, MatrixRing);
-
-module.exports = RealMatrixRing;
-
View
@@ -1,31 +0,0 @@
-
-var util = require('util');
-
-var Matrix = require('./Matrix.js');
-
-function SquareMatrix(arg) {
- var order = arg.order;
- this.getOrder = function () { return order; };
-
- //console.log('xxx'+order);
- arg.numRows = order;
- arg.numCols = order;
-
- //trace: function() { // TODO somma degli elementi della diagonale. },
- //adjoint: function() { // TODO matrice aggiunta. };
-
- Matrix.call(this, arg);
-};
-
-// TODO fai il metodo clone
-// da vedere se qua posso chiamare getField(), getNumRows(), ecc che stanno nella classe padre.
-//SquareMatrix.prototype = {
-// clone: function() {
-// return new SquareMatrix();
-// }
-//}
-
-util.inherits(SquareMatrix, Matrix);
-
-module.exports = SquareMatrix;
-
Oops, something went wrong.

0 comments on commit 7e1fac2

Please sign in to comment.