public void Test_VandermondeMatrix_4_Determinant() { VandermondeMatrix vm = new VandermondeMatrix(2, 3, 5, 7); double actual = vm.GetDeterminant(); double expected = (7 - 5) * (7 - 3) * (7 - 2) * (5 - 3) * (5 - 2) * (3 - 2); Assert.Equal(expected, actual); }
public void Test_VandermondeMatrix_4_Inverse() { // (-2, -39), (0, 3), (1, 6), (3, 36) VandermondeMatrix vm = new VandermondeMatrix(-2, 0, 1, 3); Vector y = new Vector(new double[] { -39, 3, 6, 36 }); double determinant = vm.GetDeterminant(); Assert.NotEqual(0, determinant); Matrix m = vm.GetInverse(); Vector actual = m * y; // p(x) = 2x^3-4x^2+5x+3 Assert.Equal(3, actual[0]); Assert.Equal(5, actual[1]); Assert.Equal(-4, actual[2]); Assert.Equal(2, actual[3]); }
public void Test_VandermondeMatrix_4_Inverse2() { // (0, 3), (1, 6), (3, 36), (4, 9) VandermondeMatrix vm = new VandermondeMatrix(0, 1, 3, 4); Vector y = new Vector(new double[] { 3, 6, 36, 9 }); double determinant = vm.GetDeterminant(); Assert.NotEqual(0, determinant); Matrix m = vm.GetInverse(); Vector actual = m * y; // p(x) = -4.5x^3 + 22x^2 -14.5x + 3 Assert.Equal(3, actual[0]); Assert.Equal(-14.5, actual[1]); Assert.Equal(0, 22 - actual[2], 14); Assert.Equal(-4.5, actual[3]); }