@Test public void testMultiplication () { TriDiagonalMatrix M = new TriDiagonalMatrix(1, 1, 1, 1, 1, 1, 1, 1, 1, 1); Vector X = new Vector(1, 2, 3, 4); Vector Y = M.times(X); Assert.assertEquals(4, Y.size()); Assert.assertEquals(3, Y.coord(0), EPSILON); Assert.assertEquals(6, Y.coord(1), EPSILON); Assert.assertEquals(9, Y.coord(2), EPSILON); Assert.assertEquals(7, Y.coord(3), EPSILON); M = new TriDiagonalMatrix(1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2); X = new Vector(1, 2, 3, 4, 5, 6); Y = M.times(X); Assert.assertEquals(6, Y.size()); Assert.assertEquals(5, Y.coord(0), EPSILON); Assert.assertEquals(26, Y.coord(1), EPSILON); Assert.assertEquals(65, Y.coord(2), EPSILON); Assert.assertEquals(94, Y.coord(3), EPSILON); Assert.assertEquals(73, Y.coord(4), EPSILON); Assert.assertEquals(27, Y.coord(5), EPSILON); M = new TriDiagonalMatrix(1, 2, 1, 2); X = new Vector(3, 4); Y = M.times(X); Assert.assertEquals(2, Y.size()); Assert.assertEquals(11, Y.coord(0), EPSILON); Assert.assertEquals(11, Y.coord(1), EPSILON); }
public Vector times (Vector X) { if (X.size() != _n) throw new IllegalArgumentException("Illegal result - matrix multiplication can't result in a vector of size " + X.size()); double[] r = new double[_n]; for (int i = 0; i < _n; ++i) { double entry = 0; if (i > 0) entry += _a[i] * X.coord(i - 1); entry += _b[i] * X.coord(i); if (i < _n - 1) entry += _c[i] * X.coord(i + 1); r[i] = entry; } return new Vector(r); }
TriDiagonalMatrix { public Vector times (Vector X) { if (X.size() != _n) throw new IllegalArgumentException("Illegal result - matrix multiplication can't result in a vector of size " + X.size()); double[] r = new double[_n]; for (int i = 0; i < _n; ++i) { double entry = 0; if (i > 0) entry += _a[i] * X.coord(i - 1); entry += _b[i] * X.coord(i); if (i < _n - 1) entry += _c[i] * X.coord(i + 1); r[i] = entry; } return new Vector(r); } }
TriDiagonalMatrix { public Vector times (Vector X) { if (X.size() != _n) throw new IllegalArgumentException("Illegal result - matrix multiplication can't result in a vector of size " + X.size()); double[] r = new double[_n]; for (int i = 0; i < _n; ++i) { double entry = 0; if (i > 0) entry += _a[i] * X.coord(i - 1); entry += _b[i] * X.coord(i); if (i < _n - 1) entry += _c[i] * X.coord(i + 1); r[i] = entry; } return new Vector(r); } TriDiagonalMatrix(double... entries); }
TriDiagonalMatrix { public Vector times (Vector X) { if (X.size() != _n) throw new IllegalArgumentException("Illegal result - matrix multiplication can't result in a vector of size " + X.size()); double[] r = new double[_n]; for (int i = 0; i < _n; ++i) { double entry = 0; if (i > 0) entry += _a[i] * X.coord(i - 1); entry += _b[i] * X.coord(i); if (i < _n - 1) entry += _c[i] * X.coord(i + 1); r[i] = entry; } return new Vector(r); } TriDiagonalMatrix(double... entries); void setPrecision(double precision); Vector solve(Vector d); Vector times(Vector X); }
TriDiagonalMatrix { public Vector times (Vector X) { if (X.size() != _n) throw new IllegalArgumentException("Illegal result - matrix multiplication can't result in a vector of size " + X.size()); double[] r = new double[_n]; for (int i = 0; i < _n; ++i) { double entry = 0; if (i > 0) entry += _a[i] * X.coord(i - 1); entry += _b[i] * X.coord(i); if (i < _n - 1) entry += _c[i] * X.coord(i + 1); r[i] = entry; } return new Vector(r); } TriDiagonalMatrix(double... entries); void setPrecision(double precision); Vector solve(Vector d); Vector times(Vector X);  }