var matrix=function(options){
if (!(this instanceof arguments.callee)) {
return new arguments.callee(options);
}
this.init(options);
};
matrix.prototype={
init:function(options){
this.matrix=options.matrix;
},
add:function(mtx){
var omtx=this.matrix;
var newMtx=[];
if(!mtx.length||!mtx[0].length||mtx.length!=omtx.length||mtx[0].length!=omtx[0].length){
return;
}
for(var i=0,len1=omtx.length;i<len1;i++){
var rowMtx=omtx[i];
newMtx.push([]);
for(var j=0,len2=rowMtx.length;j<len2;j++){
newMtx[i][j]=rowMtx[j]+mtx[i][j];
}
}
this.matrix=newMtx;
return this;
},
multiply:function(mtx){
var omtx = mtx.matrix;
var mtx = this.matrix;
var newMtx=[];
if(!isNaN(mtx)){
for(var i=0,len1=omtx.length;i<len1;i++){
var rowMtx=omtx[i];
newMtx.push([]);
for(var j=0,len2=rowMtx.length;j<len2;j++){
omtx[i][j]*=mtx;
}
}
return new matrix({matrix:newMtx});
}
var sum=0;
for(var i=0,len1=omtx.length;i<len1;i++){
var rowMtx=omtx[i];
newMtx.push([]);
for(var m=0,len3=mtx[0].length;m<len3;m++){
for(var j=0,len2=rowMtx.length;j<len2;j++){
sum+=omtx[i][j]*mtx[j][m];
}
newMtx[newMtx.length-1].push(sum);
sum=0;
}
}
this.matrix=newMtx;
return this;
}
};
this.Matrix=matrix;