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

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    DROT_TEST tests DROT.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    15 May 2006
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int N = 6;

        double[] x = new double[N];
        double[] y = new double[N];

        for (int i = 0; i < N; i++)
        {
            x[i] = i + 1;
        }

        for (int i = 0; i < N; i++)
        {
            y[i] = (i + 1) * (i + 1) - 12;
        }

        Console.WriteLine("");
        Console.WriteLine("DROT_TEST");
        Console.WriteLine("  DROT carries out a Givens rotation.");
        Console.WriteLine("");
        Console.WriteLine("  X and Y");
        Console.WriteLine("");
        for (int i = 0; i < N; i++)
        {
            Console.WriteLine("  "
                              + (i + 1).ToString(CultureInfo.InvariantCulture).PadLeft(6) + "  "
                              + x[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + "  "
                              + y[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }

        double c = 0.5;
        double s = Math.Sqrt(1.0 - c * c);

        BLAS1D.drot(N, ref x, 1, ref y, 1, c, s);
        Console.WriteLine("");
        Console.WriteLine("  DROT ( N, X, 1, Y, 1, " + c + "," + s + " )");
        Console.WriteLine("");
        for (int i = 0; i < N; i++)
        {
            Console.WriteLine("  "
                              + (i + 1).ToString(CultureInfo.InvariantCulture).PadLeft(6) + "  "
                              + x[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + "  "
                              + y[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }

        for (int i = 0; i < N; i++)
        {
            x[i] = i + 1;
        }

        for (int i = 0; i < N; i++)
        {
            y[i] = (i + 1) * (i + 1) - 12;
        }

        c = x[0] / Math.Sqrt(x[0] * x[0] + y[0] * y[0]);
        s = y[0] / Math.Sqrt(x[0] * x[0] + y[0] * y[0]);
        BLAS1D.drot(N, ref x, 1, ref y, 1, c, s);
        Console.WriteLine("");
        Console.WriteLine("  DROT ( N, X, 1, Y, 1, " + c + "," + s + " )");
        Console.WriteLine("");
        for (int i = 0; i < N; i++)
        {
            Console.WriteLine("  "
                              + (i + 1).ToString(CultureInfo.InvariantCulture).PadLeft(6) + "  "
                              + x[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + "  "
                              + y[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }
    }