//>>built
define("dojox/math/matrix",["dojo","dojox"],function(n,m){n.getObject("math.matrix",!0,m);n.mixin(m.math.matrix,{iDF:0,ALMOST_ZERO:1E-10,multiply:function(b,c){var f=b.length,d=b[0].length,a=c.length,e=c[0].length;if(d!=a)return console.warn("Can't multiply matricies of sizes "+d+","+f+" and "+e+","+a),[[0]];for(var a=[],g=0;g<f;g++){a[g]=[];for(var k=0;k<e;k++)for(var h=a[g][k]=0;h<d;h++)a[g][k]+=b[g][h]*c[h][k]}return a},product:function(){if(0==arguments.length)return console.warn("can't multiply 0 matrices!"),
1;for(var b=arguments[0],c=1;c<arguments.length;c++)b=this.multiply(b,arguments[c]);return b},sum:function(){if(0==arguments.length)return console.warn("can't sum 0 matrices!"),0;var b=this.copy(arguments[0]),c=b.length;if(0==c)return console.warn("can't deal with matrices of 0 rows!"),0;var f=b[0].length;if(0==f)return console.warn("can't deal with matrices of 0 cols!"),0;for(var d=1;d<arguments.length;++d){var a=arguments[d];if(a.length!=c||a[0].length!=f)return console.warn("can't add matrices of different dimensions: first dimensions were "+
c+"x"+f+", current dimensions are "+a.length+"x"+a[0].length),0;for(var e=0;e<c;e++)for(var g=0;g<f;g++)b[e][g]+=a[e][g]}return b},inverse:function(b){if(1==b.length&&1==b[0].length)return[[1/b[0][0]]];var c=b.length,f=this.create(c,c),d=this.adjoint(b),a=this.determinant(b);b=0;if(0==a)return console.warn("Determinant Equals 0, Not Invertible."),[[0]];b=1/a;for(a=0;a<c;a++)for(var e=0;e<c;e++)f[a][e]=b*d[a][e];return f},determinant:function(b){if(b.length!=b[0].length)return console.warn("Can't calculate the determinant of a non-squre matrix!"),
0;var c=b.length,f=1;b=this.upperTriangle(b);for(var d=0;d<c;d++){var a=b[d][d];if(Math.abs(a)<this.ALMOST_ZERO)return 0;f*=a}return f*=this.iDF},upperTriangle:function(b){b=this.copy(b);var c=0,c=0,f=b.length,d=1;this.iDF=1;for(var a=0;a<f-1;a++){"number"!=typeof b[a][a]&&console.warn("non-numeric entry found in a numeric matrix: m["+a+"]["+a+"]\x3d"+b[a][a]);for(var d=1,e=0;0==b[a][a]&&!e;)if(a+d>=f)this.iDF=0,e=1;else{for(var g=0;g<f;g++)c=b[a][g],b[a][g]=b[a+d][g],b[a+d][g]=c;d++;this.iDF*=-1}for(d=
a+1;d<f;d++)if("number"!=typeof b[d][a]&&console.warn("non-numeric entry found in a numeric matrix: m["+d+"]["+a+"]\x3d"+b[d][a]),"number"!=typeof b[a][d]&&console.warn("non-numeric entry found in a numeric matrix: m["+a+"]["+d+"]\x3d"+b[a][d]),0!=b[a][a])for(c=-1*b[d][a]/b[a][a],e=a;e<f;e++)b[d][e]=c*b[a][e]+b[d][e]}return b},create:function(b,c,f){f=f||0;for(var d=[],a=0;a<c;a++){d[a]=[];for(var e=0;e<b;e++)d[a][e]=f}return d},ones:function(b,c){return this.create(b,c,1)},zeros:function(b,c){return this.create(b,
c)},identity:function(b,c){c=c||1;for(var f=[],d=0;d<b;d++){f[d]=[];for(var a=0;a<b;a++)f[d][a]=d==a?c:0}return f},adjoint:function(b){var c=b.length;if(1>=c)return console.warn("Can't find the adjoint of a matrix with a dimension less than 2"),[[0]];if(b.length!=b[0].length)return console.warn("Can't find the adjoint of a non-square matrix"),[[0]];for(var f=this.create(c,c),d=this.create(c-1,c-1),a=0,e=0,g=0,k=0,h=a=0;h<c;h++)for(var l=0;l<c;l++){for(a=g=0;a<c;a++)if(a!=h){for(e=k=0;e<c;e++)e!=l&&
(d[g][k]=b[a][e],k++);g++}a=this.determinant(d);f[h][l]=Math.pow(-1,h+l)*a}return this.transpose(f)},transpose:function(b){for(var c=this.create(b.length,b[0].length),f=0;f<b.length;f++)for(var d=0;d<b[f].length;d++)c[d][f]=b[f][d];return c},format:function(b,c){c=c||5;for(var f=b.length,d=0<f?b[0].length:0,a="",e=0;e<f;e++){for(var a=a+"| ",g=0;g<d;g++){var k=c,h=Math.pow(10,k),h=(Math.round(b[e][g]*h)/h).toString();"-"!=h.charAt(0)&&(h=" "+h);for(-1<h.indexOf(".")&&(h+=".");h.length<k+3;)h+="0";
a+=h+" "}a+="|\n"}return a},copy:function(b){for(var c=b.length,f=b[0].length,d=this.create(f,c),a=0;a<c;a++)for(var e=0;e<f;e++)d[a][e]=b[a][e];return d},scale:function(b,c){b=this.copy(b);for(var f=b.length,d=b[0].length,a=0;a<f;a++)for(var e=0;e<d;e++)b[a][e]*=c;return b}});return m.math.matrix});