Ejemplo n.º 1
0
    private static void bernstein_matrix_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    BERNSTEIN_MATRIX_TEST tests BERNSTEIN_MATRIX.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    26 January 2016
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        Console.WriteLine("");
        Console.WriteLine("BERNSTEIN_MATRIX_TEST");
        Console.WriteLine("  BERNSTEIN_MATRIX returns a matrix A which transforms a");
        Console.WriteLine("  polynomial coefficient vector from the power basis to");
        Console.WriteLine("  the Bernstein basis.");

        int n = 5;

        double[] a = BernsteinPolynomial.bernstein_matrix(n);
        typeMethods.r8mat_print(n, n, a, "  Bernstein matrix A of order 5:");
    }
Ejemplo n.º 2
0
    private static void bernstein_matrix_inverse_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    BERNSTEIN_MATRIX_INVERSE_TEST tests BERNSTEIN_MATRIX_INVERSE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    26 January 2016
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        Console.WriteLine("");
        Console.WriteLine("BERNSTEIN_MATRIX_INVERSE_TEST");
        Console.WriteLine("  BERNSTEIN_MATRIX_INVERSE computes the inverse of the");
        Console.WriteLine("  Bernstein matrix A.");
        Console.WriteLine("");
        Console.WriteLine("     N     ||A||       ||inv(A)|| ||I-A*inv(A)||");
        Console.WriteLine("");

        for (int n = 5; n <= 15; n++)
        {
            double[] a = BernsteinPolynomial.bernstein_matrix(n);
            double   a_norm_frobenius = typeMethods.r8mat_norm_fro(n, n, a);

            double[] b = BernsteinPolynomial.bernstein_matrix_inverse(n);
            double   b_norm_frobenius = typeMethods.r8mat_norm_fro(n, n, b);

            double[] c = typeMethods.r8mat_mm_new(n, n, n, a, b);
            double   error_norm_frobenius = typeMethods.r8mat_is_identity(n, c);

            Console.WriteLine("  " + n.ToString().PadLeft(4)
                              + "  " + a_norm_frobenius.ToString().PadLeft(14)
                              + "  " + b_norm_frobenius.ToString().PadLeft(14)
                              + "  " + error_norm_frobenius.ToString().PadLeft(14) + "");
        }
    }
Ejemplo n.º 3
0
    private static void bernstein_matrix_determinant_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    BERNSTEIN_MATRIX_DETERMINANT_TEST tests BERNSTEIN_MATRIX_DETERMINANT.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    26 January 2016
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        Console.WriteLine("");
        Console.WriteLine("BERNSTEIN_MATRIX_DETERMINANT_TEST");
        Console.WriteLine("  BERNSTEIN_MATRIX_DETERMINANT computes the determinant of");
        Console.WriteLine("  the Bernstein matrix.");
        Console.WriteLine("");
        Console.WriteLine("     N         ||A||          det(A)");
        Console.WriteLine("                              computed");
        Console.WriteLine("");

        for (int n = 5; n <= 15; n++)
        {
            double[] a = BernsteinPolynomial.bernstein_matrix(n);
            double   a_norm_frobenius = typeMethods.r8mat_norm_fro(n, n, a);

            double d1 = BernsteinPolynomial.bernstein_matrix_determinant(n);

            Console.WriteLine("  " + n.ToString().PadLeft(4)
                              + "  " + a_norm_frobenius.ToString().PadLeft(14)
                              + "  " + d1.ToString().PadLeft(14) + "");
        }
    }
Ejemplo n.º 4
0
    private static void bernstein_matrix_test2()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    BERNSTEIN_MATRIX_TEST2 tests BERNSTEIN_MATRIX.
    //
    //  Discussion:
    //
    //    Here we use the Bernstein matrix to describe a Bernstein polynomial
    //    in terms of the standard monomials.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    27 January 2016
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        Console.WriteLine("");
        Console.WriteLine("TEST06");
        Console.WriteLine("  BERNSTEIN_MATRIX returns a matrix A which");
        Console.WriteLine("  transforms a polynomial coefficient vector");
        Console.WriteLine("  from the the Bernstein basis to the power basis.");
        Console.WriteLine("  We can use this to get explicit values of the");
        Console.WriteLine("  4-th degree Bernstein polynomial coefficients as");
        Console.WriteLine("");
        Console.WriteLine("    b(4,K)(X) = C4 * x^4");
        Console.WriteLine("              + C3 * x^3");
        Console.WriteLine("              + C2 * x^2");
        Console.WriteLine("              + C1 * x");
        Console.WriteLine("              + C0 * 1");

        int n = 5;

        Console.WriteLine("");
        Console.WriteLine("     K       C4           C3            C2" +
                          "            C1             C0");
        Console.WriteLine("");

        double[] a = BernsteinPolynomial.bernstein_matrix(n);
        double[] x = new double[n];

        for (int k = 0; k < n; k++)
        {
            for (int i = 0; i < n; i++)
            {
                x[i] = 0.0;
            }

            x[k] = 1.0;

            double[] ax = typeMethods.r8mat_mv_new(n, n, a, x);

            string cout = "  " + k.ToString().PadLeft(4) + "  ";
            for (int i = 0; i < n; i++)
            {
                cout += "  " + ax[i].ToString().PadLeft(14);
            }

            Console.WriteLine(cout);
        }
    }