1 Clazz.declarePackage ("JU");
2 c$ = Clazz.decorateAsClass (function () {
6 if (!Clazz.isClassDefined ("JU.Matrix.LUDecomp")) {
7 JU.Matrix.$Matrix$LUDecomp$ ();
9 Clazz.instantialize (this, arguments);
10 }, JU, "Matrix", null, Cloneable);
11 Clazz.makeConstructor (c$,
13 this.a = (a == null ? Clazz.newDoubleArray (m, n, 0) : a);
17 Clazz.defineMethod (c$, "getRowDimension",
21 Clazz.defineMethod (c$, "getColumnDimension",
25 Clazz.defineMethod (c$, "getArray",
29 Clazz.defineMethod (c$, "getArrayCopy",
31 var x = Clazz.newDoubleArray (this.m, this.n, 0);
32 for (var i = this.m; --i >= 0; ) for (var j = this.n; --j >= 0; ) x[i][j] = this.a[i][j];
37 Clazz.defineMethod (c$, "copy",
39 var x = new JU.Matrix (null, this.m, this.n);
41 for (var i = this.m; --i >= 0; ) for (var j = this.n; --j >= 0; ) c[i][j] = this.a[i][j];
46 Clazz.overrideMethod (c$, "clone",
50 Clazz.defineMethod (c$, "getSubmatrix",
51 function (i0, j0, nrows, ncols) {
52 var x = new JU.Matrix (null, nrows, ncols);
54 for (var i = nrows; --i >= 0; ) for (var j = ncols; --j >= 0; ) xa[i][j] = this.a[i0 + i][j0 + j];
59 Clazz.defineMethod (c$, "getMatrixSelected",
61 var x = new JU.Matrix (null, r.length, n);
63 for (var i = r.length; --i >= 0; ) {
65 for (var j = n; --j >= 0; ) xa[i][j] = b[j];
70 Clazz.defineMethod (c$, "transpose",
72 var x = new JU.Matrix (null, this.n, this.m);
74 for (var i = this.m; --i >= 0; ) for (var j = this.n; --j >= 0; ) c[j][i] = this.a[i][j];
79 Clazz.defineMethod (c$, "add",
81 return this.scaleAdd (b, 1);
83 Clazz.defineMethod (c$, "sub",
85 return this.scaleAdd (b, -1);
87 Clazz.defineMethod (c$, "scaleAdd",
89 var x = new JU.Matrix (null, this.m, this.n);
92 for (var i = this.m; --i >= 0; ) for (var j = this.n; --j >= 0; ) xa[i][j] = ba[i][j] * scale + this.a[i][j];
97 Clazz.defineMethod (c$, "mul",
99 if (b.m != this.n) return null;
100 var x = new JU.Matrix (null, this.m, b.n);
103 for (var j = b.n; --j >= 0; ) for (var i = this.m; --i >= 0; ) {
104 var arowi = this.a[i];
106 for (var k = this.n; --k >= 0; ) s += arowi[k] * ba[k][j];
113 Clazz.defineMethod (c$, "inverse",
115 return Clazz.innerTypeInstance (JU.Matrix.LUDecomp, this, null, this.m, this.n).solve (JU.Matrix.identity (this.m, this.m), this.n);
117 Clazz.defineMethod (c$, "trace",
120 for (var i = Math.min (this.m, this.n); --i >= 0; ) t += this.a[i][i];
124 c$.identity = Clazz.defineMethod (c$, "identity",
126 var x = new JU.Matrix (null, m, n);
128 for (var i = Math.min (m, n); --i >= 0; ) xa[i][i] = 1;
132 Clazz.defineMethod (c$, "getRotation",
134 return this.getSubmatrix (0, 0, this.m - 1, this.n - 1);
136 Clazz.defineMethod (c$, "getTranslation",
138 return this.getSubmatrix (0, this.n - 1, this.m - 1, 1);
140 c$.newT = Clazz.defineMethod (c$, "newT",
141 function (r, asColumn) {
142 return (asColumn ? new JU.Matrix ( Clazz.newArray (-1, [ Clazz.newDoubleArray (-1, [r.x]), Clazz.newDoubleArray (-1, [r.y]), Clazz.newDoubleArray (-1, [r.z])]), 3, 1) : new JU.Matrix ( Clazz.newArray (-1, [ Clazz.newDoubleArray (-1, [r.x, r.y, r.z])]), 1, 3));
144 Clazz.overrideMethod (c$, "toString",
147 for (var i = 0; i < this.m; i++) {
149 for (var j = 0; j < this.n; j++) s += " " + this.a[i][j];
156 c$.$Matrix$LUDecomp$ = function () {
158 c$ = Clazz.decorateAsClass (function () {
159 Clazz.prepareCallback (this, arguments);
163 Clazz.instantialize (this, arguments);
164 }, JU.Matrix, "LUDecomp");
165 Clazz.makeConstructor (c$,
167 this.LU = this.b$["JU.Matrix"].getArrayCopy ();
168 this.piv = Clazz.newIntArray (a, 0);
169 for (var c = a; --c >= 0; ) this.piv[c] = c;
173 var e = Clazz.newDoubleArray (a, 0);
174 for (var f = 0; f < b; f++) {
175 for (var g = a; --g >= 0; ) e[g] = this.LU[g][f];
177 for (var h = a; --h >= 0; ) {
179 var i = Math.min (h, f);
181 for (var k = i; --k >= 0; ) j += d[k] * e[k];
186 for (var j = a; --j > f; ) if (Math.abs (e[j]) > Math.abs (e[i])) i = j;
189 for (var k = b; --k >= 0; ) {
190 var l = this.LU[i][k];
191 this.LU[i][k] = this.LU[f][k];
195 this.piv[i] = this.piv[f];
197 this.pivsign = -this.pivsign;
198 }if ( new Boolean (f < a & this.LU[f][f] != 0.0).valueOf ()) for (var k = a; --k > f; ) this.LU[k][f] /= this.LU[f][f];
202 Clazz.defineMethod (c$, "solve",
204 for (var c = 0; c < b; c++) if (this.LU[c][c] == 0) return null;
207 var e = a.getMatrixSelected (this.piv, d);
209 for (var g = 0; g < b; g++) for (var h = g + 1; h < b; h++) for (var i = 0; i < d; i++) f[h][i] -= f[g][i] * this.LU[h][g];
213 for (var j = b; --j >= 0; ) {
214 for (var k = d; --k >= 0; ) f[j][k] /= this.LU[j][j];
216 for (var l = j; --l >= 0; ) for (var m = d; --m >= 0; ) f[l][m] -= f[j][m] * this.LU[l][j];