@Test public void test2DSolving () { Vector vNaN = new Vector(Double.NaN, Double.NaN); TriDiagonalMatrix M; Vector D; Vector X; M = new TriDiagonalMatrix(0, 0, 0, 0); D = new Vector(0, 0); X = M.solve(D); Assert.assertEquals(2, X.size()); Assert.assertFalse(Double.isNaN(X.coord(0))); Assert.assertFalse(Double.isNaN(X.coord(1))); D = new Vector(1, 0); X = M.solve(D); Assert.assertEquals(vNaN, X); D = new Vector(0, 1); X = M.solve(D); Assert.assertEquals(vNaN, X); M = new TriDiagonalMatrix(0, 1, 0, 1); D = new Vector(1, 0); X = M.solve(D); Assert.assertEquals(vNaN, X); D = new Vector(0, 1); X = M.solve(D); Assert.assertEquals(vNaN, X); D = new Vector(2, 2); X = M.solve(D); Assert.assertEquals(2, X.size()); Assert.assertFalse(Double.isNaN(X.coord(0))); Assert.assertEquals(2.0, X.coord(1), EPSILON); M = new TriDiagonalMatrix(1, 1, 0, 0); D = new Vector(4, 0); X = M.solve(D); Assert.assertEquals(2, X.size()); Assert.assertEquals(4.0, X.coord(0) + X.coord(1), EPSILON); D = new Vector(1, 0); X = M.solve(D); Assert.assertEquals(2, X.size()); Assert.assertEquals(1.0, X.coord(0) + X.coord(1), EPSILON); D = new Vector(0, 1); X = M.solve(D); Assert.assertEquals(vNaN, X); D = new Vector(1, 1); X = M.solve(D); Assert.assertEquals(vNaN, X); M = new TriDiagonalMatrix(1, 0, 1, 0); D = new Vector(1, 0); X = M.solve(D); Assert.assertEquals(vNaN, X); D = new Vector(0, 1); X = M.solve(D); Assert.assertEquals(vNaN, X); D = new Vector(2, 2); X = M.solve(D); Assert.assertEquals(2, X.size()); Assert.assertEquals(2.0, X.coord(0), EPSILON); Assert.assertFalse(Double.isNaN(X.coord(1))); M = new TriDiagonalMatrix(0, 0, 1, 1); D = new Vector(1, 0); X = M.solve(D); Assert.assertEquals(vNaN, X); D = new Vector(0, 4); X = M.solve(D); Assert.assertEquals(2, X.size()); Assert.assertEquals(4.0, X.coord(0) + X.coord(1), EPSILON); D = new Vector(1, 1); X = M.solve(D); Assert.assertEquals(vNaN, X); M = new TriDiagonalMatrix(0, 1, 2, 3); D = new Vector(2, 12); X = M.solve(D); Assert.assertEquals(new Vector(3, 2), X); M = new TriDiagonalMatrix(1, 0, 2, 3); D = new Vector(3, 12); X = M.solve(D); Assert.assertEquals(new Vector(3, 2), X); M = new TriDiagonalMatrix(2, 1, 0, 3); D = new Vector(8, 6); X = M.solve(D); Assert.assertEquals(new Vector(3, 2), X); M = new TriDiagonalMatrix(3, 1, 2, 0); D = new Vector(11, 6); X = M.solve(D); Assert.assertEquals(new Vector(3, 2), X); M = new TriDiagonalMatrix(1, 2, 3, 4); D = new Vector(7, 17); X = M.solve(D); Assert.assertEquals(new Vector(3, 2), X); }
public Vector solve (Vector d) { if (d.size() != _n) throw new IllegalArgumentException("Attempt to find tri-diagonal solution with improper-sized vector"); double[] x = new double[_n]; solve(d, x, 0, (_n > 0 ? _b[0] : 0), (_n > 1 ? _c[0] : 0), (_n > 0 ? d.coord(0) : 0)); return new Vector(x); }
TriDiagonalMatrix { public Vector solve (Vector d) { if (d.size() != _n) throw new IllegalArgumentException("Attempt to find tri-diagonal solution with improper-sized vector"); double[] x = new double[_n]; solve(d, x, 0, (_n > 0 ? _b[0] : 0), (_n > 1 ? _c[0] : 0), (_n > 0 ? d.coord(0) : 0)); return new Vector(x); } }
TriDiagonalMatrix { public Vector solve (Vector d) { if (d.size() != _n) throw new IllegalArgumentException("Attempt to find tri-diagonal solution with improper-sized vector"); double[] x = new double[_n]; solve(d, x, 0, (_n > 0 ? _b[0] : 0), (_n > 1 ? _c[0] : 0), (_n > 0 ? d.coord(0) : 0)); return new Vector(x); } TriDiagonalMatrix(double... entries); }
TriDiagonalMatrix { public Vector solve (Vector d) { if (d.size() != _n) throw new IllegalArgumentException("Attempt to find tri-diagonal solution with improper-sized vector"); double[] x = new double[_n]; solve(d, x, 0, (_n > 0 ? _b[0] : 0), (_n > 1 ? _c[0] : 0), (_n > 0 ? d.coord(0) : 0)); return new Vector(x); } TriDiagonalMatrix(double... entries); void setPrecision(double precision); Vector solve(Vector d); Vector times(Vector X); }
TriDiagonalMatrix { public Vector solve (Vector d) { if (d.size() != _n) throw new IllegalArgumentException("Attempt to find tri-diagonal solution with improper-sized vector"); double[] x = new double[_n]; solve(d, x, 0, (_n > 0 ? _b[0] : 0), (_n > 1 ? _c[0] : 0), (_n > 0 ? d.coord(0) : 0)); return new Vector(x); } TriDiagonalMatrix(double... entries); void setPrecision(double precision); Vector solve(Vector d); Vector times(Vector X);  }