Example #1
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="position">座標</param>
 /// <param name="text">表示文字列</param>
 /// <param name="difficulty">難易度</param>
 public Difficulties(Vector2DF position, string text, Dif difficulty)
 {
     ReturnDif = difficulty;
     Font      = BigFont;
     Position  = position;
     Text      = text;
 }
Example #2
0
    public static void roots_to_r8poly(int nroots, double[] roots, ref int nc, ref double[] c)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    ROOTS_TO_R8POLY converts polynomial roots to polynomial coefficients.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    06 September 2004
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int NROOTS, the number of roots specified.
    //
    //    Input, double ROOTS[NROOTS], the roots.
    //
    //    Output, integer *NC, the order of the polynomial, which will be NROOTS+1.
    //
    //    Output, double C[*NC], the coefficients of the polynomial.
    //
    {
        int i;

        nc = nroots + 1;
        //
        //  Initialize C to (0, 0, ..., 0, 1).
        //  Essentially, we are setting up a divided difference table.
        //
        double[] xtab = new double[nroots + 1];
        for (i = 0; i < nc - 1; i++)
        {
            xtab[i] = roots[i];
        }

        xtab[nc - 1] = 0.0;

        for (i = 0; i < nc - 1; i++)
        {
            c[i] = 0.0;
        }

        c[nc - 1] = 1.0;
        //
        //  Convert to standard polynomial form by shifting the abscissas
        //  of the divided difference table to 0.
        //
        Dif.dif_shift_zero(nc, ref xtab, ref c);
    }
Example #3
0
    public static void data_to_r8poly(int ntab, double[] xtab, double[] ytab, ref double[] c)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    DATA_TO_R8POLY computes the coefficients of a polynomial interpolating data.
    //
    //  Discussion:
    //
    //    Space can be saved by using a single array for both the C and
    //    YTAB parameters.  In that case, the coefficients will
    //    overwrite the Y data without interfering with the computation.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    05 September 2004
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Reference:
    //
    //    Carl deBoor,
    //    A Practical Guide to Splines,
    //    Springer, 2001,
    //    ISBN: 0387953663,
    //    LC: QA1.A647.v27.
    //
    //  Parameters:
    //
    //    Input, int NTAB, the number of data points.
    //
    //    Input, double XTAB[NTAB], YTAB[NTAB], the data values.
    //
    //    Output, double C[NTAB], the coefficients of the polynomial that passes
    //    through the data (XTAB,YTAB).  C(0) is the constant term.
    //
    {
        if (!typeMethods.r8vec_distinct(ntab, xtab))
        {
            Console.WriteLine("");
            Console.WriteLine("DATA_TO_R8POLY - Fatal error!");
            Console.WriteLine("  Two entries of XTAB are equal.");
            return;
        }

        data_to_dif(ntab, xtab, ytab, ref c);

        Dif.dif_to_r8poly(ntab, xtab, c, ref c);
    }
Example #4
0
    private static void dif_basis_deriv_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    Dif.dif_basis_deriv_test tests Dif.dif_basis_deriv;
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    01 June 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int nd = 3;

        Console.WriteLine("");
        Console.WriteLine("Dif.dif_basis_deriv_test");
        Console.WriteLine("  Dif.dif_basis_deriv() computes difference tables for");
        Console.WriteLine("  the first derivative of each Lagrange basis.");

        double[] xd  = new double[nd];
        double[] xdp = new double[nd - 1];
        double[] ddp = new double[(nd - 1) * nd];

        xd[0] = -2.0;
        xd[1] = 1.0;
        xd[2] = 5.0;

        Dif.dif_basis_deriv(nd, xd, ref xdp, ref ddp);
        //
        //  Because the difference tables were shifted to all 0 abscissas,
        //  they contain the polynomial coefficients.
        //
        typeMethods.r8mat_transpose_print(nd - 1, nd, ddp,
                                          "  Lagrange basis derivative polynomial coefficients:");

        double[] c = new double[nd - 1];
        Dif.dif_to_r8poly(nd - 1, xdp, ddp, ref c, diftabIndex: +0 * (nd - 1));
        typeMethods.r8poly_print(nd - 1, c, "  P1'=-(2x-6)/21");

        Dif.dif_to_r8poly(nd - 1, xdp, ddp, ref c, diftabIndex:  +1 * (nd - 1));
        typeMethods.r8poly_print(nd - 1, c, "  P2'=-(2x-3)/12");

        Dif.dif_to_r8poly(nd - 1, xdp, ddp, ref c, diftabIndex:  +2 * (nd - 1));
        typeMethods.r8poly_print(nd - 1, c, "  P3'=(2x+1)/28");
    }
Example #5
0
        public async Task CamDifHandlerForDatabase(VocCardVM vocCardVM)
        {
            await FillGetHtmlHelper(vocCardVM);
            await GetAudioUri();
            await GetSynonyms();

            //await GetTranslation();
            await GetFromCambridgeDic(vocCardVM.Voc.Text);

            //int contentPageStart, contentPageEnd, start, end;
            string pageContent, txt;

            using (WebClient client = new WebClient()) pageContent = client.DownloadString($"{GetHtmlHelper[1].Uri}{GetHtmlHelper[1].VocText}");

            txt = pageContent;
            Difs.Clear();
            definitions.Clear();
            while (pageContent.Contains(GetHtmlHelper[1].Key))
            {
                Dif dif = new Dif();
                var x   = await GetCambText(pageContent, GetHtmlHelper[1].Key, GetHtmlHelper[1].KeyEnd, GetHtmlHelper[1].SmallKey, GetHtmlHelper[1].SmallKeyEnd);

                dif.Text = x.Text;

                //if(string.IsNullOrEmpty(dif.Text)) definitions.Add(new Definition { Text = dif.Text, VocId = Voc.Id});

                pageContent = x.PageContent;

                while (pageContent.Contains(GetHtmlHelper[2].Key) && pageContent.IndexOf(GetHtmlHelper[2].Key) < pageContent.IndexOf(GetHtmlHelper[1].Key))
                {
                    var y = await GetCambText(pageContent, GetHtmlHelper[2].Key, GetHtmlHelper[2].KeyEnd, GetHtmlHelper[2].SmallKey, GetHtmlHelper[2].SmallKeyEnd);

                    dif.Examples.Add(y.Text);

                    //if (definitions.Count > 0) definitions[definitions.Count - 1].Examples.Add(new Example { Text = y.Text, VocId = Voc.Id});

                    pageContent = y.PageContent;
                }
                Difs.Add(dif);
                if (!string.IsNullOrEmpty(dif.Text))
                {
                    List <Example> examples = new List <Example>();
                    foreach (var ex in dif.Examples)
                    {
                        examples.Add(new Example {
                            Text = ex.Trim(), VocId = vocCardVM.Voc.Id
                        });
                    }
                    definitions.Add(new Definition {
                        Text = dif.Text.Trim(), Examples = examples, VocId = vocCardVM.Voc.Id
                    });
                }
            }
        }
Example #6
0
        public MACD(IIndicator <double> source, int shortCycle, int longCycle, int difCycle)
        {
            Source     = source;
            ShortCycle = shortCycle;
            LongCycle  = longCycle;
            DifCycle   = difCycle;
            var fast = Source.EMA(ShortCycle);
            var slow = Source.EMA(LongCycle);

            Dif          = BinaryOperation.Create(fast, slow, (a, b) => a - b);
            Dea          = Dif.EMA(difCycle);
            Macd         = BinaryOperation.Create(Dif, Dea, (a, b) => 2 * (a - b));
            Dif.Update  += Merge;
            Dea.Update  += Merge;
            Macd.Update += Merge;
        }
Example #7
0
    public static void hermite_demo(int n, double[] x, double[] y, double[] yp)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    HERMITE_DEMO computes and prints Hermite interpolant information for data.
    //
    //  Discussion:
    //
    //    Given a set of Hermite data, this routine calls HERMITE_INTERPOLANT to
    //    determine and print the divided difference table, and then DIF_TO_R8POLY to
    //    determine and print the coefficients of the polynomial in standard form.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    31 October 2011
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int N, the number of data points.
    //
    //    Input, double X[N], the abscissas.
    //
    //    Input, double Y[N], YP[N], the function and derivative
    //    values at the abscissas.
    //
    {
        int i;

        Console.WriteLine("");
        Console.WriteLine("HERMITE_DEMO");
        Console.WriteLine("  Compute coefficients CD of the Hermite polynomial");
        Console.WriteLine("  interpolant to given data (x,y,yp).");

        Console.WriteLine("");
        Console.WriteLine("  Data:");
        Console.WriteLine("              X           Y           Y'");
        Console.WriteLine("");
        for (i = 0; i < n; i++)
        {
            Console.WriteLine("  " + i.ToString(CultureInfo.InvariantCulture).PadLeft(4)
                              + "  " + x[i].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + y[i].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + yp[i].ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");
        }

        int nd = 2 * n;

        double[] xd = new double[nd];
        double[] yd = new double[nd];

        int ndp = 2 * n - 1;

        double[] xdp = new double[ndp];
        double[] ydp = new double[ndp];

        hermite_interpolant(n, x, y, yp, ref xd, ref yd, ref xdp, ref ydp);

        Console.WriteLine("");
        Console.WriteLine("  Difference table:");
        Console.WriteLine("              XD          YD");
        Console.WriteLine("");

        for (i = 0; i < nd; i++)
        {
            Console.WriteLine("  " + i.ToString(CultureInfo.InvariantCulture).PadLeft(4)
                              + "  " + xd[i].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + yd[i].ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");
        }

        Console.WriteLine("");
        Console.WriteLine("  Difference table:");
        Console.WriteLine("              XDP          YDP");
        Console.WriteLine("");
        for (i = 0; i < nd - 1; i++)
        {
            Console.WriteLine("  " + i.ToString(CultureInfo.InvariantCulture).PadLeft(4)
                              + "  " + xdp[i].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + ydp[i].ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");
        }

        double[] cd = new double[2 * n];

        Dif.dif_to_r8poly(nd, xd, yd, ref cd);

        typeMethods.r8poly_print(nd - 1, cd, "  Hermite interpolating polynomial:");
        //
        //  Verify interpolation claim!
        //
        double[] xv  = new double[n];
        double[] yv  = new double[n];
        double[] yvp = new double[n];

        for (i = 0; i < n; i++)
        {
            xv[i] = x[i];
        }

        hermite_interpolant_value(nd, xd, yd, xdp, ydp, n, xv, ref yv, ref yvp);

        Console.WriteLine("");
        Console.WriteLine("  Data Versus Interpolant:");
        Console.WriteLine("              X           Y           H           YP          HP");
        Console.WriteLine("");
        for (i = 0; i < n; i++)
        {
            Console.WriteLine("  " + i.ToString(CultureInfo.InvariantCulture).PadLeft(4)
                              + "  " + xv[i].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + y[i].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + yv[i].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + yp[i].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + yvp[i].ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");
        }
    }
Example #8
0
    private static void test02()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST02 tests DATA_TO_DIF and DIF_VAL.
    //
    //  Discussion:
    //
    //    This routine demonstrates how divided difference approximation
    //    improves with N.
    //
    //    Evaluate these polynomials at 2.5.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    18 January 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int MAXTAB = 8;

        double[] diftab = new double[MAXTAB];
        int      j;
        int      ntab;

        double[] xtab = new double[MAXTAB];
        double[] ytab = new double[MAXTAB];

        Console.WriteLine("");
        Console.WriteLine("TEST02");
        Console.WriteLine("  Approximate Y = EXP(X) using orders 1 to " + MAXTAB + ".");

        Console.WriteLine("");
        Console.WriteLine("  Original data:");
        Console.WriteLine("");
        Console.WriteLine("       X          Y");
        Console.WriteLine("");
        for (j = 0; j < MAXTAB; j++)
        {
            xtab[j] = j;
            ytab[j] = Math.Exp(xtab[j]);

            Console.WriteLine("  "
                              + xtab[j].ToString(CultureInfo.InvariantCulture).PadLeft(10) + "  "
                              + ytab[j].ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");
        }

        const double xval       = 2.5;
        double       true_value = Math.Exp(xval);

        Console.WriteLine("");
        Console.WriteLine("  Evaluate at X = " + xval + " where EXP(X) = "
                          + true_value + "");
        Console.WriteLine("");
        Console.WriteLine("  Order  Approximate Y     Error");
        Console.WriteLine("");

        for (ntab = 1; ntab <= MAXTAB; ntab++)
        {
            for (j = 0; j < ntab; j++)
            {
                xtab[j] = j;
                ytab[j] = Math.Exp(xtab[j]);
            }

            Data.data_to_dif(ntab, xtab, ytab, ref diftab);

            double yval = Dif.dif_val(ntab, xtab, diftab, xval);

            double error = yval - true_value;

            Console.WriteLine("  "
                              + ntab.ToString(CultureInfo.InvariantCulture).PadLeft(6) + "  "
                              + yval.ToString(CultureInfo.InvariantCulture).PadLeft(10) + "  "
                              + error.ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");
        }
    }
Example #9
0
    private static void dif_basis_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    Dif.dif_basis_test tests Dif.dif_basis().
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    18 January 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int NTAB = 5;

        int       i;
        int       j;
        const int nstep        = 9;
        int       pointerIndex = 0;
        const int set          = 3;

        double[] xtab = new double[NTAB];

        Console.WriteLine("");
        Console.WriteLine("Dif.dif_basis_test");
        Console.WriteLine("  Dif.dif_basis() computes Lagrange basis polynomials");
        Console.WriteLine("  in difference form.");
        Console.WriteLine("");
        //
        //  Set the base points.
        //
        typeMethods.r8vec_indicator(NTAB, ref xtab);

        typeMethods.r8vec_print(NTAB, xtab, "  The base points:");
        //
        //  Get the difference tables for the basis polynomials and print them.
        //
        double[] diftab = new double[NTAB * NTAB];

        Dif.dif_basis(NTAB, xtab, ref diftab);

        Console.WriteLine("");
        Console.WriteLine("  The table of difference vectors defining the basis polynomials.");
        Console.WriteLine("  Each ROW represents a polynomial.");
        Console.WriteLine("");

        double[] pointer = diftab;

        for (i = 0; i < NTAB; i++)
        {
            string cout = "  ";
            for (j = 0; j < NTAB; j++)
            {
                cout += pointerIndex.ToString(CultureInfo.InvariantCulture).PadLeft(10) + "  ";
                pointerIndex++;
            }

            Console.WriteLine(cout);
        }

        //
        //  Evaluate basis polynomial 3 at a set of points.
        //
        Console.WriteLine("");
        Console.WriteLine("  Evaluate basis polynomial #" + set + " at a set of points.");
        Console.WriteLine("");
        Console.WriteLine("      X        Y");
        Console.WriteLine("");

        const double xhi = NTAB;
        const double xlo = 1.0;

        //
        //  Advance pointer to beginning of data for basis polynomial SET.
        //
        pointer      = diftab;
        pointerIndex = 0;
        for (i = 1; i < set; i++)
        {
            for (j = 1; j <= NTAB; j++)
            {
                pointerIndex++;
            }
        }

        for (i = 1; i <= nstep; i++)
        {
            double xval = ((nstep - i) * xlo
                           + (i - 1) * xhi)
                          / (nstep - 1);

            double yval = Dif.dif_val(NTAB, xtab, pointer, xval, diftabIndex: pointerIndex);

            Console.WriteLine("  "
                              + xval.ToString(CultureInfo.InvariantCulture).PadLeft(10) + "  "
                              + yval.ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");
        }
    }
Example #10
0
 // Use this for initialization
 void Start()
 {
     rigidbody2D = GetComponent <Rigidbody2D>();
     Difcs       = GetComponent <Dif>();
 }
Example #11
0
    private static void dif_basis_derivk_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    Dif.dif_basis_derivk_test tests DIF_BASIS_DERIVK;
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    04 June 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        // ReSharper disable once JoinDeclarationAndInitializer
        double[]  ddp;
        const int k  = 2;
        const int nd = 5;

        Console.WriteLine("");
        Console.WriteLine("Dif.dif_basis_derivk_test");
        Console.WriteLine("  DIF_BASIS_DERIVK computes difference tables for");
        Console.WriteLine("  the K-th derivative of each Lagrange basis.");

        double[] xd  = new double[nd];
        double[] xdp = new double[nd - k];
        ddp = new double[(nd - k) * nd];

        xd[0] = 1.0;
        xd[1] = 2.0;
        xd[2] = 3.0;
        xd[3] = 4.0;
        xd[4] = 5.0;

        Dif.dif_basis_derivk(nd, xd, k, ref xdp, ref ddp);
        //
        //  Because the difference tables were shifted to all 0 abscissas,
        //  they contain the polynomial coefficients.
        //
        typeMethods.r8mat_transpose_print(nd - k, nd, ddp,
                                          "  Lagrange basis K-th derivative polynomial coefficients:");

        double[] c = new double[nd - k];

        Dif.dif_to_r8poly(nd - k, xdp, ddp, ref c, diftabIndex: +0 * (nd - k));
        typeMethods.r8poly_print(nd - k, c, "  P1''=(12x^2-84x+142)/24");

        Dif.dif_to_r8poly(nd - k, xdp, ddp, ref c, diftabIndex:  +1 * (nd - k));
        typeMethods.r8poly_print(nd - k, c, "  P2''=-2x^2+13x-59/3");

        Dif.dif_to_r8poly(nd - k, xdp, ddp, ref c, diftabIndex:  +2 * (nd - k));
        typeMethods.r8poly_print(nd - k, c, "  P3''=3x^2-18x+49/2");

        Dif.dif_to_r8poly(nd - k, xdp, ddp, ref c, diftabIndex:  +3 * (nd - k));
        typeMethods.r8poly_print(nd - k, c, "  P4''=-2x^2+11x-41/3");

        Dif.dif_to_r8poly(nd - k, xdp, ddp, ref c, diftabIndex:  +4 * (nd - k));
        typeMethods.r8poly_print(nd - k, c, "  P5''=(6x^2-30x+35)/12");
    }
Example #12
0
    public static double[] hermite_interpolant_rule(int n, double a, double b, double[] x)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    HERMITE_INTERPOLANT_RULE: quadrature rule for a Hermite interpolant.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    31 October 2011
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int N, the number of abscissas.
    //
    //    Input, double A, B, the integration limits.
    //
    //    Input, double X[N], the abscissas.
    //
    //    Output, double HERMITE_INTERPOLANT_RULE[2*N], the quadrature
    //    coefficients, given as pairs for function and derivative values
    //    at each abscissa.
    //
    {
        int i;

        double[] y  = new double[n];
        double[] yp = new double[n];

        int nd = 2 * n;

        double[] c  = new double[nd];
        double[] w  = new double[nd];
        double[] xd = new double[nd];
        double[] yd = new double[nd];

        int ndp = 2 * n - 1;

        double[] xdp = new double[ndp];
        double[] ydp = new double[ndp];

        for (i = 0; i < n; i++)
        {
            y[i]  = 0.0;
            yp[i] = 0.0;
        }

        int k = 0;

        for (i = 0; i < n; i++)
        {
            y[i] = 1.0;
            hermite_interpolant(n, x, y, yp, ref xd, ref yd, ref xdp, ref ydp);
            Dif.dif_to_r8poly(nd, xd, yd, ref c);
            double a_value = typeMethods.r8poly_ant_val(n, c, a);
            double b_value = typeMethods.r8poly_ant_val(n, c, b);
            w[k] = b_value - a_value;
            y[i] = 0.0;
            k   += 1;

            yp[i] = 1.0;
            hermite_interpolant(n, x, y, yp, ref xd, ref yd, ref xdp, ref ydp);
            Dif.dif_to_r8poly(nd, xd, yd, ref c);
            a_value = typeMethods.r8poly_ant_val(n, c, a);
            b_value = typeMethods.r8poly_ant_val(n, c, b);
            w[k]    = b_value - a_value;
            yp[i]   = 0.0;
            k      += 1;
        }

        return(w);
    }
Example #13
0
    private static void test05()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST05 interpolates the Runge function using Chebyshev spaced data.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    31 October 2011
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int n;

        Console.WriteLine("");
        Console.WriteLine("TEST05");
        Console.WriteLine("  HERMITE computes the Hermite interpolant to data.");
        Console.WriteLine("  Here, f(x) is the Runge function");
        Console.WriteLine("  and the data is evaluated at Chebyshev spaced points.");
        Console.WriteLine("  As N increases, the maximum error decreases.");
        Console.WriteLine("");
        Console.WriteLine("     N     Max | F(X) - H(F(X)) |");
        Console.WriteLine("");

        for (n = 3; n <= 15; n += 2)
        {
            double[] y  = new double[n];
            double[] yp = new double[n];

            int      nd = 2 * n;
            double[] xd = new double[nd];
            double[] yd = new double[nd];

            int      ndp = 2 * n - 1;
            double[] xdp = new double[ndp];
            double[] ydp = new double[ndp];

            int ns = 10 * (n - 1) + 1;

            double   xlo = -5.0;
            double   xhi = +5.0;
            double[] x   = typeMethods.r8vec_chebyshev_new(n, xlo, xhi);

            int i;
            for (i = 0; i < n; i++)
            {
                y[i]  = 1.0 / (1.0 + x[i] * x[i]);
                yp[i] = -2.0 * x[i] / (1.0 + x[i] * x[i]) / (1.0 + x[i] * x[i]);
            }

            Hermite.hermite_interpolant(n, x, y, yp, ref xd, ref yd, ref xdp, ref ydp);
            //
            //  Compare exact and interpolant at sample points.
            //
            double[] xs = typeMethods.r8vec_linspace_new(ns, xlo, xhi);

            double[] ys = Dif.dif_vals(nd, xd, yd, ns, xs);

            double max_dif = 0.0;
            for (i = 0; i < ns; i++)
            {
                double xt = xs[i];
                double yt = 1.0 / (1.0 + xt * xt);
                max_dif = Math.Max(max_dif, Math.Abs(ys[i] - yt));
            }

            Console.WriteLine("  " + n.ToString(CultureInfo.InvariantCulture).PadLeft(4)
                              + "  " + max_dif.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }
    }
Example #14
0
    private static void dif_derivk_table_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    Dif.dif_derivk_table_test tests Dif.dif_derivk_table;
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    01 June 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int i;
        int j;

        Console.WriteLine("");
        Console.WriteLine("Dif.dif_derivk_table_test");
        Console.WriteLine("  Dif.dif_derivk_table() computes the K-th derivative");
        Console.WriteLine("  for a divided difference table.");
        //
        //  Set the 0 data points.
        //
        int n0 = 5;

        double[] x0 = new double[n0];
        double[] f0 = new double[n0];
        for (i = 0; i < 5; i++)
        {
            x0[i] = i - 2;
        }

        //
        //  Set data for x^4/24+x^3/3+x^2/2+x+1
        //
        for (j = 0; j < n0; j++)
        {
            f0[j] = 1.0;
            for (i = 4; 1 <= i; i--)
            {
                f0[j] = f0[j] * x0[j] / i + 1.0;
            }
        }

        //
        //  Compute the difference table.
        //
        double[] d0 = new double[n0];
        Data.data_to_dif(n0, x0, f0, ref d0);
        Dif.dif_print(n0, x0, d0, "  The divided difference polynomial P0:");

        double[] c0 = new double[n0];
        Dif.dif_to_r8poly(n0, x0, d0, ref c0);

        typeMethods.r8poly_print(n0, c0, "  Using DIF_TO_R8POLY");
        //
        //  Compute the difference table for the K=1 derivative.
        //
        int k  = 1;
        int n1 = n0 - k;

        double[] x1 = new double[n1];
        double[] d1 = new double[n1];
        Dif.dif_derivk_table(n0, x0, d0, k, x1, ref d1);
        //
        //  Compute the difference table for the K=2 derivative.
        //
        k = 2;
        int n2 = n0 - k;

        double[] x2 = new double[n2];
        double[] d2 = new double[n2];
        Dif.dif_derivk_table(n0, x0, d0, k, x2, ref d2);
        //
        //  Compute the difference table for the K=3 derivative.
        //
        k = 3;
        int n3 = n0 - k;

        double[] x3 = new double[n3];
        double[] d3 = new double[n3];
        Dif.dif_derivk_table(n0, x0, d0, k, x3, ref d3);
        //
        //  Compute the difference table for the K=4 derivative.
        //
        k = 4;
        int n4 = n0 - k;

        double[] x4 = new double[n4];
        double[] d4 = new double[n4];
        Dif.dif_derivk_table(n0, x0, d0, k, x4, ref d4);
        //
        //  Evaluate all 5 polynomials.
        //
        Console.WriteLine("");
        Console.WriteLine("  Evaluate difference tables for the function P0");
        Console.WriteLine("  and its first four derivatives, P1...P4.");
        Console.WriteLine("");
        Console.WriteLine("      X         P0        P1        P2        P3        P4");
        Console.WriteLine("");

        for (i = 0; i <= 10; i++)
        {
            double x  = i / 5.0;
            double y0 = Dif.dif_val(n0, x0, d0, x);
            double y1 = Dif.dif_val(n1, x1, d1, x);
            double y2 = Dif.dif_val(n2, x2, d2, x);
            double y3 = Dif.dif_val(n3, x3, d3, x);
            double y4 = Dif.dif_val(n4, x4, d4, x);
            Console.WriteLine("  " + x.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + "  " + y0.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + "  " + y1.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + "  " + y2.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + "  " + y3.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + "  " + y4.ToString(CultureInfo.InvariantCulture).PadLeft(8) + "");
        }
    }
Example #15
0
    private static void test18()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST18 tests ROOTS_TO_DIF and DIF_TO_R8POLY.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    18 January 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int MAXROOTS = 4;

        double[] c      = new double[MAXROOTS + 1];
        double[] diftab = new double[MAXROOTS + 1];
        int      ntab   = 0;

        double[] roots = new double[MAXROOTS];
        double[] xtab  = new double[MAXROOTS + 1];

        Console.WriteLine("");
        Console.WriteLine("TEST18");
        Console.WriteLine("  ROOTS_TO_DIF computes a divided difference");
        Console.WriteLine("  polynomial with the given roots;");
        Console.WriteLine("  DIF_TO_R8POLY converts it to a standard form polynomial.");
        Console.WriteLine("");

        int nroots = 1;

        roots[0] = 3.0;
        typeMethods.r8vec_print(nroots, roots, "  The roots:");

        Roots.roots_to_dif(nroots, roots, ref ntab, ref xtab, ref diftab);
        Dif.dif_to_r8poly(ntab, xtab, diftab, ref c);
        typeMethods.r8poly_print(ntab, c, "  The polynomial:");

        nroots   = 2;
        roots[0] = 3.0;
        roots[1] = 1.0;
        typeMethods.r8vec_print(nroots, roots, "  The roots:");

        Roots.roots_to_dif(nroots, roots, ref ntab, ref xtab, ref diftab);
        Dif.dif_to_r8poly(ntab, xtab, diftab, ref c);
        typeMethods.r8poly_print(ntab, c, "  The polynomial:");

        nroots   = 3;
        roots[0] = 3.0;
        roots[1] = 1.0;
        roots[2] = 2.0;
        typeMethods.r8vec_print(nroots, roots, "  The roots:");

        Roots.roots_to_dif(nroots, roots, ref ntab, ref xtab, ref diftab);
        Dif.dif_to_r8poly(ntab, xtab, diftab, ref c);
        typeMethods.r8poly_print(ntab, c, "  The polynomial:");

        nroots   = 4;
        roots[0] = 3.0;
        roots[1] = 1.0;
        roots[2] = 2.0;
        roots[3] = 4.0;
        typeMethods.r8vec_print(nroots, roots, "  The roots:");

        Roots.roots_to_dif(nroots, roots, ref ntab, ref xtab, ref diftab);
        Dif.dif_to_r8poly(ntab, xtab, diftab, ref c);
        typeMethods.r8poly_print(ntab, c, "  The polynomial:");
    }
Example #16
0
    private static void test01()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST01 tests DIF*;
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    01 June 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int MAXTAB = 10;

        double[] diftab  = new double[MAXTAB];
        double[] diftab2 = new double[MAXTAB];
        double[] diftab3 = new double[MAXTAB];
        int      i;
        int      ntab3 = 0;

        double[] xtab  = new double[MAXTAB];
        double[] xtab2 = new double[MAXTAB];
        double[] xtab3 = new double[MAXTAB];
        double[] ytab  = new double[MAXTAB];

        Console.WriteLine("");
        Console.WriteLine("TEST01");
        Console.WriteLine("  DATA_TO_DIF_DISPLAY sets up a difference table");
        Console.WriteLine("  and displays intermediate calculations;");
        Console.WriteLine("  DIF_APPEND appends a new data point;");
        Console.WriteLine("  DIF_ANTIDERIV computes the antiderivative;");
        Console.WriteLine("  DIF_DERIV_TABLE computes the derivative;");
        Console.WriteLine("  DIF_SHIFT_ZERO shifts all the abscissas to 0;");
        Console.WriteLine("  DIF_VAL evaluates at a point;");
        Console.WriteLine("");
        //
        //  Set XTAB, YTAB to X, X^2.
        //
        int ntab = 4;

        for (i = 0; i < ntab; i++)
        {
            xtab[i] = i + 1;
            ytab[i] = xtab[i] * xtab[i];
        }

        Data.data_to_dif_display(ntab, xtab, ytab, ref diftab);

        Dif.dif_print(ntab, xtab, diftab, "  The divided difference polynomial:");
        //
        //  Add (5,25) to the table.
        //
        Console.WriteLine("");
        Console.WriteLine("  DIF_APPEND can add the data (5,25) to the table.");
        Console.WriteLine("");

        double xval = 5.0;
        double yval = 25.0;

        Dif.dif_append(ntab, xtab, diftab, xval, yval, ref ntab, ref xtab, ref diftab);

        Dif.dif_print(ntab, xtab, diftab,
                      "  The updated divided difference polynomial:");
        //
        //  Evaluate the polynomial at 2.5.
        //
        Console.WriteLine("");
        Console.WriteLine("  DIF_VAL can evaluate the table at a point.");
        Console.WriteLine("");

        xval = 2.5;

        yval = Dif.dif_val(ntab, xtab, diftab, xval);

        Console.WriteLine("");
        Console.WriteLine("  DIF_VAL reports P(" + xval + ") = " + yval + "");
        //
        //  Shift the base to zero.
        //
        Dif.dif_shift_zero(ntab, ref xtab, ref diftab);

        Dif.dif_print(ntab, xtab, diftab,
                      "  The divided difference table after DIF_SHIFT_ZERO:");
        //
        //  Compute a table for the derivative.
        //
        int ntab2 = ntab - 1;

        Dif.dif_deriv_table(ntab, xtab, diftab, ref xtab2, diftab2);

        Dif.dif_print(ntab2, xtab2, diftab2,
                      "  The divided difference table for the derivative:");

        yval = Dif.dif_val(ntab2, xtab2, diftab2, xval);

        Console.WriteLine("");
        Console.WriteLine("  DIF_VAL reports P'(" + xval + ") = " + yval + "");
        //
        //  Compute the antiderivative.
        //
        Dif.dif_antideriv(ntab, xtab, diftab, ref ntab3, xtab3, ref diftab3);

        Dif.dif_print(ntab3, xtab3, diftab3,
                      "  The divided difference table for the antiderivative:");

        yval = Dif.dif_val(ntab3, xtab3, diftab3, xval);

        Console.WriteLine("");
        Console.WriteLine("  DIF_VAL reports (Anti)P(" + xval + ") = " + yval + "");
    }
Example #17
0
    private static void test05()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST05 tests DATA_TO_DIF_DISPLAY, DIF_PRINT, DIF_SHIFT_ZERO, DIF_TO_R8POLY;
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    18 January 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int MAXTAB = 10;

        double[] c       = new double[MAXTAB];
        double[] diftab1 = new double[MAXTAB];
        double[] diftab2 = new double[MAXTAB];
        int      i;

        double[] xtab1 = new double[MAXTAB];
        double[] xtab2 = new double[MAXTAB];
        double[] ytab1 = new double[MAXTAB];
        double[] ytab2 = new double[MAXTAB];

        Console.WriteLine("");
        Console.WriteLine("TEST05");
        Console.WriteLine("  DIF_TO_R8POLY converts a difference table to a polynomial;");
        Console.WriteLine("  DIF_SHIFT_ZERO shifts a divided difference table to 0;");
        Console.WriteLine("");
        Console.WriteLine("  These are equivalent operations");
        Console.WriteLine("");
        //
        //  Set XTAB, YTAB to X, F(X)
        //
        const int ntab = 4;

        for (i = 0; i < ntab; i++)
        {
            double x = i + 1;
            xtab1[i] = x;
            xtab2[i] = x;
            ytab1[i] = -4.0 + x * (3.0 + x * (-2.0 + x));
            ytab2[i] = ytab1[i];
        }

        //
        //  Compute and display the finite difference table.
        //
        Data.data_to_dif_display(ntab, xtab1, ytab1, ref diftab1);

        Data.data_to_dif_display(ntab, xtab2, ytab2, ref diftab2);
        //
        //  Examine the corresponding polynomial.
        //
        Dif.dif_print(ntab, xtab1, diftab1, "  The divided difference table:");
        //
        //  Shift to zero using DIF_SHIFT_ZERO.
        //
        Dif.dif_shift_zero(ntab, ref xtab1, ref diftab1);

        typeMethods.r8poly_print(ntab, diftab1, "  The polynomial using DIF_SHIFT_ZERO:");
        //
        //  Shift to zero using DIF_TO_R8POLY.
        //
        Dif.dif_to_r8poly(ntab, xtab2, diftab2, ref c);

        typeMethods.r8poly_print(ntab, c, "  The polynomial using DIF_TO_R8POLY:");
    }
Example #18
0
        public Event(DateTime ClockStart, DateTime ClockEnd, int ClockRunTime, System.Xml.Linq.XDocument XMLEvents, ref CrashHandler Crash)
        {
            ch = Crash;
            events = new Dictionary<string, List<EventItem>>();
            clock = new PartyClock(ClockStart, ClockEnd, ClockRunTime);
            Util.ShowClock = true;
            sound = new Sound(true);
            text = new Text2D();
            chess = new Chess();
            sf = new Starfield(150);

            intro = new Intro(ref sound, ref text);
            outro = new Outro(ref sound);

            advent = new Advent(ref sound);
            birthday = new Birthday(ref sound, ref text, ref chess);
            xmas = new Christmas(ref sound);
            smurf = new Datasmurf(ref sound, ref text); // random
            dif = new Dif(ref chess, ref sound); // random
            fbk = new Fbk(ref sound); // random
            hw = new Halloween(ref chess, ref sound, 25);
            lucia = new Lucia(ref chess, ref sound);
            newyear = new NewYear();
            richard = new RMS(ref sound, ref text); // random
            scroller = new Scroller(ref chess, ref sf, ref text); // random
            semla = new Semla();
            sune = new SuneAnimation(ref sound, ref text);
            tl = new TurboLogo(ref sound, ref chess, (OpenGL.Util.SpringOrFall.Equals("Spring")? true:false)/*((ClockStart.Month >= 1 && ClockStart.Month <= 8)? false:true)*/ ); // vilken termin är det? jan till början av augusti VT, resten HT... random
            valentine = new Valentine(ref sound);
            wl = new WinLinux(ref chess); //random
            creators = new Self(ref sound); // random
            bb = new BB(ref sound); // random
            GM = new GummiBears(ref sound);
            NDay = new National(ref chess, ref sound);
            easter = new Easter(ref sound);
            hajk = new Hajk(ref sound);
            mid = new Midsummer(ref sound);
            vaf = new Vaffla();
            wp = new Walpurgis();
            crayfish = new CrayFish();

            ts = new TeknatStyle(ref chess, ref sound, ref text);
            m = new Matrix(ref text);
            q = new Quiz(ref text, false, ref sound);
            talepsin = new Talespin(ref sound);
            cd = new ChipAndDale(ref sound, ref chess);
            nerd = new Nerdy(ref chess, ref sound);
            trex = new Trex(ref sound);
            sailormoon = new Sailormoon(ref sound,ref chess);
            gb = new GhostBusters(ref sound);
            zelda = new Zelda(ref sound, ref chess);
            tardis = new Tardis(ref sound);
            f**k = new F**k(ref sound, ref chess);

            silverFang = new SilverFang(ref sound);
            mt = new MoraT(ref sound);

            swine = new Swine(ref chess, ref text);
            tjall = new Tjall(ref chess, ref text);

            ronja = new Ronja(ref sound);
            emil = new Emil(ref sound);
            djungelboken = new Djungelboken(ref sound);
            fabbe = new Fabbe(ref sound);
            drink = new Drink(ref sound);
            frozen = new Frozen(ref sound);

            eventCurrent = null; // event item for events to be triggerd in clock_NewDate
            //randomEvent = new List<string>(new string[] { "starfield", "SuneAnimation", "TurboLogo", "Datasmurf", "WinLinux", "Scroller", "BB", "GummiBears", "TeknatStyle", "Matrix"});
            randomEvent = new List<string>(new string[] { "starfield", "Nerdy", "Talespin", "Sailormoon", "GhostBusters", "Zelda", "Tardis", "F**k", "SilverFang", "MoraT" });
            //new stuff
             List<UtilXML.EventData> ed = UtilXML.Loadeffectdata();

            // TODO: Make a clean list with all events allowed to be used implement so that it is actaully usable instead of a switch at the bottom of this file.
            Dictionary<string, Effect> effects = new Dictionary<string, Effect>()
            {
                {"SuneAnimation", new Effect(sune, ed.Find(e => e.Name == "SuneAnimation"))},
                {"Dif",new Effect(dif, ed.Find(e => e.Name == "Dif"))},
                {"Fbk",new Effect(fbk, ed.Find(e => e.Name == "Fbk"))},
                {"TurboLogo",new Effect(tl, ed.Find(e => e.Name == "TurboLogo"))},
                {"Datasmurf", new Effect(smurf, ed.Find(e => e.Name == "Datasmurf"))},
                {"RMS",new Effect(richard, ed.Find(e => e.Name == "RMS"))},
                {"WinLinux",new Effect(wl, ed.Find(e => e.Name == "WinLinux"))},
                {"Scroller",new Effect(scroller, ed.Find(e => e.Name == "Scroller"))},
                {"Self",new Effect(creators, ed.Find(e => e.Name == "Self"))},
                {"BB",new Effect(bb, ed.Find(e => e.Name == "BB"))},
                {"GummiBears",new Effect(GM, ed.Find(e => e.Name == "GummiBears"))},
                {"Hajk",new Effect(hajk, ed.Find(e => e.Name == "Hajk"))},
                {"TeknatStyle",new Effect(ts, ed.Find(e => e.Name == "TeknatStyle"))},
                {"Matrix",new Effect(m, ed.Find(e => e.Name == "Matrix"))},
                {"Quiz",new Effect(q, ed.Find(e => e.Name == "Quiz"))},
                {"Talespin",new Effect(talepsin, ed.Find(e => e.Name == "Talespin"))},
                {"ChipDale",new Effect(cd, ed.Find(e => e.Name == "ChipDale"))},
                {"Nerdy",new Effect(nerd, ed.Find(e => e.Name == "Nerdy"))},
              /*  {"Trex",new Effect(trex, ed.Find(e => e.Name == "Trex"))},*/
                {"Sailormoon",new Effect(sailormoon, ed.Find(e => e.Name == "Sailormoon"))},
                {"GhostBusters",new Effect(gb, ed.Find(e => e.Name == "GhostBusters"))},
                {"Zelda",new Effect(zelda, ed.Find(e => e.Name == "Zelda"))},
                {"Tardis",new Effect(tardis, ed.Find(e => e.Name == "Tardis"))},
                {"F**k",new Effect(f**k, ed.Find(e => e.Name == "F**k"))},
                {"SilverFang",new Effect(silverFang, ed.Find(e => e.Name == "SilverFang"))},
                {"MoraT",new Effect(mt, ed.Find(e => e.Name == "MoraT"))},
                {"Ronja",new Effect(ronja, ed.Find(e => e.Name == "Ronja"))},
                {"Emil",new Effect(emil, ed.Find(e => e.Name == "Emil"))},
                {"Djungelboken",new Effect(djungelboken, ed.Find(e => e.Name == "Djungelboken"))},
                {"Fabbe",new Effect(fabbe, ed.Find(e => e.Name == "Fabbe"))},
                {"Drink",new Effect(drink, ed.Find(e => e.Name == "Drink"))},
                {"Frozen",new Effect(drink, ed.Find(e => e.Name == "Frozen"))}
            };

            runEffectInMonth = new Dictionary<string, List<objdata>>();

            string[] months = Util.monthlist();
            int counter;
            foreach (KeyValuePair<string, Effect> pair in effects)
            {
                counter = 0;
                foreach (bool b in pair.Value.RunAllowedlist)
                {
                    if (b == true)
                    {
                        if (!runEffectInMonth.ContainsKey(months[counter]))
                        {
                            runEffectInMonth.Add(months[counter], new List<objdata>());
                        }

                        runEffectInMonth[months[counter]].Add(new objdata(pair.Key, pair.Value.Vetolist[counter], pair.Value.Priolist[counter], pair.Value.Runslist[counter]));
                    }
                    counter++;
                }
            }

            clock.NewDate += clock_NewDate; // Event listener

            if (ch.CrashDialogResult == System.Windows.Forms.DialogResult.Yes)
            {
                clock.clock = ch.CrashClock;
            }

            string name, date, type;
            // Event dates setup
            foreach (var item in XMLEvents.Descendants("event"))
            {
                name = item.Element("name").Value;
                date = item.Element("date").Value;
                type = item.Element("type").Value.ToLower();
                EventItem ei = new EventItem(name, type, date);
                if (!events.ContainsKey(date))
                {
                    List<EventItem> list = new List<EventItem>(); // seems most bad in my eyes...
                    events.Add(date, list);
                }

                for (int i = 0; i < events[date].Count; i++)
                {
                    EventItem e = events[date][i];
                    if ("birthday".Equals(e.Type) && "birthday".Equals(ei.Type))
                    {
                        e.Name += "\n\n" + ei.Name;
                        events[date][i] = e;
                    }
                }
                events[date].Add(ei);
                name = date = type = string.Empty;
            }

            // this needs to be fixed nicer...
            if (events.ContainsKey(ClockEnd.ToShortDateString()))
            {
                events[ClockEnd.ToShortDateString()].Clear(); // force this to be top..
                events[ClockEnd.ToShortDateString()].Add( new EventItem("outro", "outro", ClockEnd.ToShortDateString()) );
            }
            else
            {
                events.Add(ClockEnd.ToShortDateString(), new List<EventItem>() { new EventItem("outro", "outro", ClockEnd.ToShortDateString()) });
            }

            // Random effects on dates with no effects and check against new list of allowed things for them...
            DateTime dt = ClockStart;
            bool star = (Util.Rnd.Next(0, 1000) < 500 ? true:false); // make this random at the start too?
            int num = 0;

            while (dt <= ClockEnd)
            {
                date = dt.ToShortDateString();
                if (!events.ContainsKey(date))
                {
                    EventItem ei;

                    if (num == 0 || num == 1)
                    {
                        ei = new EventItem("starfield", "random", date);
                    }
                    else
                    {
                        //ei = new EventItem(randomEvent[Util.Rnd.Next(1, randomEvent.Count)], "random", date);

                        string month = "";
                        if (dt != null)
                            month = dt.Month.ToString();

                        switch (month)
                        {
                            case "1": month = "jan"; break;
                            case "2": month = "feb"; break;
                            case "3": month = "mar"; break;
                            case "4": month = "apr"; break;
                            case "5": month = "maj"; break;
                            case "6": month = "jun"; break;
                            case "7": month = "jul"; break;
                            case "8": month = "aug"; break;
                            case "9": month = "sep"; break;
                            case "10": month = "okt"; break;
                            case "11": month = "nov"; break;
                            case "12": month = "dec"; break;
                        }//switch

                        if (runEffectInMonth.ContainsKey(month))
                        {
                            List<objdata> mobj = runEffectInMonth[month];

                            List<objdata> vetolist = new List<objdata>();
                            List<objdata> novetolist = new List<objdata>();

                            foreach (objdata n in mobj)
                            {

                                if ("Quiz".Equals(n.Name) && eventnum == 4)
                                {
                                    n.vetoAgain();
                                    eventnum = 0;
                                }

                                if (n.Veto == true)
                                {
                                    if (n.Runs > 0)
                                        vetolist.Add(n);
                                }
                                else
                                {
                                    if (n.Runs > 0)
                                        novetolist.Add(n);
                                }
                            }

                            vetolist.Sort();
                            novetolist.Sort();

                            if (vetolist.Count > 0)
                            {
                                ei = new EventItem(vetolist[0].Name, "random", date);
                                vetolist[0].noMoreVeto();
                            }
                            else if (novetolist.Count > 0)
                            {
                                ei = new EventItem(novetolist[0].Name, "random", date);
                                novetolist[0].decRuns();
                                if (eventnum < 4)
                                    eventnum++;
                            }
                            else
                            {
                                ei = new EventItem(randomEvent[Util.Rnd.Next(1, randomEvent.Count)], "random", date);
                            }
                        }
                        else
                        {
                            ei = new EventItem(randomEvent[Util.Rnd.Next(1, randomEvent.Count)], "random", date);
                        }
                    }

                    num++;
                    if (num == 3)
                    {
                        num = 0;
                    }
                    ei = new EventItem("Self", "random", date); // this is for debuging new events
                    events.Add(date, new List<EventItem>());
                    events[date].Add(ei);
                }

                dt = dt.AddDays(1);
                date = string.Empty;
            }
        }
Example #19
0
    public static void hermite_interpolant(int n, double[] x, double[] y, double[] yp,
                                           ref double[] xd, ref double[] yd, ref double[] xdp, ref double[] ydp)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    HERMITE_INTERPOLANT sets up a divided difference table from Hermite data.
    //
    //  Discussion:
    //
    //    The polynomial represented by the divided difference table can be
    //    evaluated by calling DIF_VALS.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    31 October 2011
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Reference:
    //
    //    Carl deBoor,
    //    A Practical Guide to Splines,
    //    Springer, 2001,
    //    ISBN: 0387953663,
    //    LC: QA1.A647.v27.
    //
    //  Parameters:
    //
    //    Input, int N, of items of data
    //    ( X(I), Y(I), YP(I) ).
    //
    //    Input, double X[N], the abscissas.
    //    These values must be distinct.
    //
    //    Input, double Y[N], YP[N], the function and derivative values.
    //
    //    Output, double XD[2*N], YD[2*N], the divided difference table
    //    for the interpolant value.
    //
    //    Output, double XDP[2*N-1], YDP[2*N-1], the divided difference
    //    table for the interpolant derivative.
    //
    {
        int i;
        int ndp = 0;
        //
        //  Copy the data.
        //
        int nd = 2 * n;

        for (i = 0; i < n; i++)
        {
            xd[0 + i * 2] = x[i];
            xd[1 + i * 2] = x[i];
        }

        //
        //  Carry out the first step of differencing.
        //
        yd[0] = y[0];
        for (i = 1; i < n; i++)
        {
            yd[0 + 2 * i] = (y[i] - y[i - 1]) / (x[i] - x[i - 1]);
        }

        for (i = 0; i < n; i++)
        {
            yd[1 + 2 * i] = yp[i];
        }

        //
        //  Carry out the remaining steps in the usual way.
        //
        for (i = 2; i < nd; i++)
        {
            int j;
            for (j = nd - 1; i <= j; j--)
            {
                yd[j] = (yd[j] - yd[j - 1]) / (xd[j] - xd[j - i]);
            }
        }

        //
        //  Compute the difference table for the derivative.
        //
        Dif.dif_deriv(nd, xd, yd, ref ndp, xdp, ref ydp);
    }