public void MultiplyMatrix() { double[] values = new double[] { 12, 23, 45, 56, 67, 89, 90, 12, 43, 65, 87, 43, 34, -12, 84, 44 }; MatrixD m = new MatrixD(4, 4, values, MatrixOrder.RowMajor); Assert.AreEqual(new MatrixD(4, 4), MatrixD.Multiply(m, new MatrixD(4, 4))); Assert.AreEqual(new MatrixD(4, 4), MatrixD.Multiply(new MatrixD(4, 4), m)); Assert.AreEqual(m, MatrixD.Multiply(m, MatrixD.CreateIdentity(4, 4))); Assert.AreEqual(m, MatrixD.Multiply(MatrixD.CreateIdentity(4, 4), m)); Assert.IsTrue(MatrixD.AreNumericallyEqual(MatrixD.CreateIdentity(4, 4), MatrixD.Multiply(m, m.Inverse))); Assert.IsTrue(MatrixD.AreNumericallyEqual(MatrixD.CreateIdentity(4, 4), MatrixD.Multiply(m.Inverse, m))); MatrixD m1 = new MatrixD(3, 4, rowMajor, MatrixOrder.RowMajor); MatrixD m2 = new MatrixD(4, 4, values, MatrixOrder.RowMajor); MatrixD result = MatrixD.Multiply(m1, m2); Assert.AreEqual(3, result.NumberOfRows); Assert.AreEqual(4, result.NumberOfColumns); for (int column = 0; column < 4; column++) for (int row = 0; row < 3; row++) Assert.AreEqual(VectorD.Dot(m1.GetRow(row), m2.GetColumn(column)), result[row, column]); }
public void GetColumn() { MatrixD m = new MatrixD(3, 4, rowMajor, MatrixOrder.RowMajor); Assert.AreEqual(new VectorD(new double[] { 1.0, 5.0, 9.0 }), m.GetColumn(0)); Assert.AreEqual(new VectorD(new double[] { 2.0, 6.0, 10.0 }), m.GetColumn(1)); Assert.AreEqual(new VectorD(new double[] { 3.0, 7.0, 11.0 }), m.GetColumn(2)); Assert.AreEqual(new VectorD(new double[] { 4.0, 8.0, 12.0 }), m.GetColumn(3)); }
public void GetColumnException2() { MatrixD m = new MatrixD(3, 4, rowMajor, MatrixOrder.RowMajor); m.GetColumn(4); }
public void SetColumn() { MatrixD m = new MatrixD(3, 4, rowMajor, MatrixOrder.RowMajor); m.SetColumn(0, new VectorD(new double[]{ 0.1, 0.2, 0.3 })); Assert.AreEqual(new VectorD(new double[]{ 0.1, 0.2, 0.3 }), m.GetColumn(0)); Assert.AreEqual(new VectorD(new double[]{ 2.0, 6.0, 10.0 }), m.GetColumn(1)); Assert.AreEqual(new VectorD(new double[]{ 3.0, 7.0, 11.0 }), m.GetColumn(2)); Assert.AreEqual(new VectorD(new double[]{ 4.0, 8.0, 12.0 }), m.GetColumn(3)); m.SetColumn(1, new VectorD(new double[] { 0.4, 0.5, 0.6 })); Assert.AreEqual(new VectorD(new double[] { 0.1, 0.2, 0.3 }), m.GetColumn(0)); Assert.AreEqual(new VectorD(new double[] { 0.4, 0.5, 0.6 }), m.GetColumn(1)); Assert.AreEqual(new VectorD(new double[] { 3.0, 7.0, 11.0 }), m.GetColumn(2)); Assert.AreEqual(new VectorD(new double[] { 4.0, 8.0, 12.0 }), m.GetColumn(3)); m.SetColumn(2, new VectorD(new double[] { 0.7, 0.8, 0.9 })); Assert.AreEqual(new VectorD(new double[] { 0.1, 0.2, 0.3 }), m.GetColumn(0)); Assert.AreEqual(new VectorD(new double[] { 0.4, 0.5, 0.6 }), m.GetColumn(1)); Assert.AreEqual(new VectorD(new double[] { 0.7, 0.8, 0.9 }), m.GetColumn(2)); Assert.AreEqual(new VectorD(new double[] { 4.0, 8.0, 12.0 }), m.GetColumn(3)); m.SetColumn(3, new VectorD(new double[] { 1.1, 1.8, 1.9 })); Assert.AreEqual(new VectorD(new double[] { 0.1, 0.2, 0.3 }), m.GetColumn(0)); Assert.AreEqual(new VectorD(new double[] { 0.4, 0.5, 0.6 }), m.GetColumn(1)); Assert.AreEqual(new VectorD(new double[] { 0.7, 0.8, 0.9 }), m.GetColumn(2)); Assert.AreEqual(new VectorD(new double[] { 1.1, 1.8, 1.9 }), m.GetColumn(3)); }