public void MatrixMultiply() { double[][] a = { new[] {1.0, 0.0, 2.0}, new[] {-1.0, 3.0, 1.0} }; double[][] b = { new[] {3.0, 1.0}, new[] {2.0, 1.0}, new[] {1.0, 0.0} }; double[][] c = { new[] {5.0, 1.0}, new[] {4.0, 2.0} }; var matrixA = new Matrix(a); var matrixB = new Matrix(b); var matrixC = new Matrix(c); var result = (Matrix) matrixA.Clone(); result.ToString(); result = MatrixMath.Multiply(matrixA, matrixB); Assert.IsTrue(result.Equals(matrixC)); double[][] a2 = { new[] {1.0, 2.0, 3.0, 4.0}, new[] {5.0, 6.0, 7.0, 8.0} }; double[][] b2 = { new[] {1.0, 2.0, 3.0}, new[] {4.0, 5.0, 6.0}, new[] {7.0, 8.0, 9.0}, new[] {10.0, 11.0, 12.0} }; double[][] c2 = { new[] {70.0, 80.0, 90.0}, new[] {158.0, 184.0, 210.0} }; matrixA = new Matrix(a2); matrixB = new Matrix(b2); matrixC = new Matrix(c2); result = MatrixMath.Multiply(matrixA, matrixB); Assert.IsTrue(result.Equals(matrixC)); matrixB.Clone(); try { MatrixMath.Multiply(matrixB, matrixA); Assert.IsTrue(false); } catch (MatrixError) { } }
public void MatrixMultiply() { double[][] a = { new[] { 1.0, 0.0, 2.0 }, new[] { -1.0, 3.0, 1.0 } }; double[][] b = { new[] { 3.0, 1.0 }, new[] { 2.0, 1.0 }, new[] { 1.0, 0.0 } }; double[][] c = { new[] { 5.0, 1.0 }, new[] { 4.0, 2.0 } }; var matrixA = new Matrix(a); var matrixB = new Matrix(b); var matrixC = new Matrix(c); var result = (Matrix)matrixA.Clone(); result.ToString(); result = MatrixMath.Multiply(matrixA, matrixB); Assert.IsTrue(result.Equals(matrixC)); double[][] a2 = { new[] { 1.0, 2.0, 3.0, 4.0 }, new[] { 5.0, 6.0, 7.0, 8.0 } }; double[][] b2 = { new[] { 1.0, 2.0, 3.0 }, new[] { 4.0, 5.0, 6.0 }, new[] { 7.0, 8.0, 9.0 }, new[] { 10.0, 11.0, 12.0 } }; double[][] c2 = { new[] { 70.0, 80.0, 90.0 }, new[] { 158.0, 184.0, 210.0 } }; matrixA = new Matrix(a2); matrixB = new Matrix(b2); matrixC = new Matrix(c2); result = MatrixMath.Multiply(matrixA, matrixB); Assert.IsTrue(result.Equals(matrixC)); matrixB.Clone(); try { MatrixMath.Multiply(matrixB, matrixA); Assert.IsTrue(false); } catch (MatrixError) { } }