Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            /*validamos entradas*/
            if (textBox2.Text == "" | textBox1.Text == "" | textBox3.Text=="" | textBox4.Text=="" )
            {
                MessageBox.Show("Uno de los recuadros esta vacio");
                Application.Exit();
            }

            /*agarramos nuestra integral, ecuacion, limites, n, h*/
               Integral integ = new Integral(textBox1.Text, textBox4.Text, textBox2.Text, textBox3.Text);

            /*lo ponemos en el recuadro de respuesta*/
            textBox5.Text = integ.Integrar().ToString();
        }
        public static double CalcularIntegralComDezPontos(Integral.Funcao funcao, double limiteInferior,
            double limiteSuperior)
        {
            double valorDaIntegral = 0.0;

            int j;
            double[] x = { 0.0, 0.1488743389, 0.4333953941, 0.6794095682, 0.8650633666, 0.9739065285 };
            //The abscissas and weights.
            //First value of each array not used.

            double[] w = { 0.0, 0.2955242247, 0.2692667193, 0.2190863625, 0.1494513491, 0.0666713443 };
            var xm = 0.5 * (limiteSuperior + limiteInferior);
            var xr = 0.5 * (limiteSuperior - limiteInferior);
            //Will be twice the average value of the function, since the
            //ten weights (five numbers above each used twice) sum to 2.
            for (j = 1; j <= 5; j++)
            {
                var dx = xr * x[j];
                valorDaIntegral += w[j] * (funcao(xm + dx) + funcao(xm - dx));
            }
            return valorDaIntegral *= xr; //Scale the answer to the range of integration.
        }
Esempio n. 3
0
    public static void hermite_exactness(int n, double[] x, double[] w, int p_max)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    HERMITE_EXACTNESS investigates exactness of Hermite quadrature.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    18 May 2014
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int N, the number of points in the rule.
    //
    //    Input, double X[N], the quadrature points.
    //
    //    Input, double W[N], the quadrature weights.
    //
    //    Input, int P_MAX, the maximum exponent.
    //    0 <= P_MAX.
    //
    {
        int p;

        Console.WriteLine("");
        Console.WriteLine("  Quadrature rule for the Hermite integral.");
        Console.WriteLine("  Rule of order N = " + n + "");
        Console.WriteLine("  Degree          Relative Error");
        Console.WriteLine("");

        double[] v = new double[n];

        for (p = 0; p <= p_max; p++)
        {
            double s = Integral.hermite_integral(p);

            int i;
            for (i = 0; i < n; i++)
            {
                v[i] = Math.Pow(x[i], p);
            }

            double q = typeMethods.r8vec_dot_product(n, w, v);

            double e = s switch
            {
                0.0 => Math.Abs(q),
                _ => Math.Abs(q - s) / Math.Abs(s)
            };

            Console.WriteLine(p.ToString(CultureInfo.InvariantCulture).PadLeft(6) + "  "
                              + e.ToString(CultureInfo.InvariantCulture).PadLeft(24) + "");
        }
    }
}
Esempio n. 4
0
    public static double evaluate(double phi, double n, double m)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    ELLIPTIC_INC_PIM evaluates the incomplete elliptic integral Pi(PHI,N,M).
    //
    //  Discussion:
    //
    //    The value is computed using Carlson elliptic integrals:
    //
    //      Pi(PHI,N,M) = integral ( 0 <= T <= PHI )
    //        dT / (1 - N sin^2(T) ) sqrt ( 1 - m * sin ( T )^2 )
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    25 June 2018
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, double PHI, N, M, the arguments.
    //
    //    Output, double ELLIPTIC_INC_PIM, the function value.
    //
    {
        int ierr = 0;

        double       cp     = Math.Cos(phi);
        double       sp     = Math.Sin(phi);
        double       x      = cp * cp;
        double       y      = 1.0 - m * sp * sp;
        const double z      = 1.0;
        double       p      = 1.0 - n * sp * sp;
        const double errtol = 1.0E-03;

        double value1 = Integral.rf(x, y, z, errtol, ref ierr);

        if (ierr != 0)
        {
            Console.WriteLine("");
            Console.WriteLine("ELLIPTIC_INC_PIM - Fatal error!");
            Console.WriteLine("  RF returned IERR = " + ierr + "");
            return(1);
        }

        double value2 = Integral.rj(x, y, z, p, errtol, ref ierr);

        if (ierr != 0)
        {
            Console.WriteLine("");
            Console.WriteLine("ELLIPTIC_INC_PIM - Fatal error!");
            Console.WriteLine("  RJ returned IERR = " + ierr + "");
            return(1);
        }

        double value = sp * value1 + n * sp * sp * sp * value2 / 3.0;

        return(value);
    }
Esempio n. 5
0
        private void DrawGraph()
        {
            chartNTime.Series[0].Points.Clear();
            int    nStart  = 10000000;
            int    nFinish = 100000000;
            int    nStep   = 20000000;
            double a       = Convert.ToDouble(tbA.Text);
            double b       = Convert.ToDouble(tbB.Text);

            Stopwatch sw = new Stopwatch();

            for (int n = nStart; n < nFinish; n += nStep)
            {
                sw.Start();

                Integral integ  = new Integral(a, b, n, SumIntegral);
                double   integ0 = integ.CalcRectangle(a, b, n, x => SumIntegral(x));


                //  Integral integ = new Integral.CalcRectangle(a, b, n, x => SumIntegral(x));

                sw.Stop();
                long time = sw.ElapsedMilliseconds;
                sw.Reset();
                chartNTime.Series[0].Points.AddXY(n, time);
            }

            ///////////////////////////////////////////////////////
            chartNTime.Series[1].Points.Clear();
            int nStart20  = 10000000;
            int nFinish20 = 100000000;
            int nStep20   = 20000000;
            // double a = Convert.ToDouble(tbA.Text);
            // double b = Convert.ToDouble(tbB.Text);

            Stopwatch sw20 = new Stopwatch();

            for (int n = nStart20; n < nFinish20; n += nStep20)
            {
                sw20.Start();

                Integral integ1  = new Integral(a, b, n, SumIntegral);
                double   integ20 = integ1.CalcRectanglePar(a, b, n);


                //  Integral integ = new Integral.CalcRectangle(a, b, n, x => SumIntegral(x));

                sw20.Stop();
                long time1 = sw20.ElapsedMilliseconds;
                sw20.Reset();
                chartNTime.Series[1].Points.AddXY(n, time1);
            }
            ///////////////////////////////////////////////////////////////////////////////

            ///////////////////////////////////////////////////////

            chartNTime2.Series[0].Points.Clear();

            int       nStart21  = 1;
            int       nFinish21 = 15;
            int       nStep21   = 1;
            int       nom       = 100000000;
            Stopwatch sw21      = new Stopwatch();

            for (int numb = nStart21; numb < nFinish21; numb += nStep21)
            {
                sw21.Start();

                Integral integ2  = new Integral(a, b, nom, SumIntegral);
                double   integ21 = integ2.CalcThreadPool(numb);
                sw21.Stop();
                long time2 = sw21.ElapsedMilliseconds;
                sw21.Reset();
                chartNTime2.Series[0].Points.AddXY(numb, time2);
            }
            ///////////////////////////////////////////////////////////////////////////////
            DrawGraph22(a, b);
            DrawGraph30(a, b);
            DrawGraph31(a, b);
            DrawGraph40(a, b);
            DrawGraph41(a, b);
        }
Esempio n. 6
0
    private static void rd_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    RD_TEST tests RD.
    //
    //  Discussion:
    //
    //    This driver tests the function for the
    //    integral RD(X,Y,Z), which is symmetric in X and Y.  The first
    //    twelve sets of values of X, Y, Z are extreme points of the region of
    //    valid arguments defined by the machine-dependent constants LOLIM
    //    and UPLIM.  The values of LOLIM, UPLIM, X, Y, Z, and ERRTOL (see
    //    comments in void) may be used on most machines but provide a
    //    severe test of robustness only on the ibm 360/370 series.  The
    //    thirteenth set tests the failure exit.  The fourteenth set is a
    //    check value: RD(0,2,1) = 3B = 3(PI)/4A, where A and B are the
    //    lemniscate constants.  The remaining sets show the dependence
    //    on Z when Y = 1 (no loss of generality because of homogeneity)
    //    and X = 0.5 (midway between the complete case X = 0 and the
    //    degenerate case X = Y).
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 June 2018
    //
    //  Author:
    //
    //    Original FORTRAN77 version by Bille Carlson, Elaine Notis.
    //    C++ version by John Burkardt.
    //
    {
        int i;
        int ierr = 0;

        double[] x =
        {
            0.00E+00,
            0.55E-78,
            0.00E+00,
            0.55E-78,
            0.00E+00,
            0.55E-78,
            0.00E+00,
            0.55E-78,
            3.01E-51,
            3.01E-51,
            0.99E+48,
            0.99E+48,
            0.00E+00,
            0.00E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00
        };

        double[] y =
        {
            6.01E-51,
            6.01E-51,
            6.01E-51,
            6.01E-51,
            0.99E+48,
            0.99E+48,
            0.99E+48,
            0.99E+48,
            3.01E-51,
            3.01E-51,
            0.99E+48,
            0.99E+48,
            3.01E-51,
            2.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00
        };

        double[] z =
        {
            6.01E-51,
            6.01E-51,
            0.99E+48,
            0.99E+48,
            6.01E-51,
            6.01E-51,
            0.99E+48,
            0.99E+48,
            6.01E-51,
            0.99E+48,
            6.01E-51,
            0.99E+48,
            1.00E+00,
            1.00E+00,
            1.00E-10,
            1.00E-05,
            1.00E-02,
            1.00E-01,
            2.00E-01,
            5.00E-01,
            1.00E+00,
            2.00E+00,
            5.00E+00,
            1.00E+01,
            1.00E+02,
            1.00E+05,
            1.00E+10
        };

        Console.WriteLine("");
        Console.WriteLine("RD_TEST");
        Console.WriteLine("  RD evaluates the Carlson elliptic integral");
        Console.WriteLine("  of the second kind, RD(X,Y,Z)");
        Console.WriteLine("");
        Console.WriteLine("               X                          Y" +
                          "                          Z                         RD(X,Y,Z)");
        Console.WriteLine("");

        const double errtol = 1.0E-03;

        for (i = 0; i < 27; i++)
        {
            double eliptc = Integral.rd(x[i], y[i], z[i], errtol, ref ierr);
            string cout   = x[i].ToString(CultureInfo.InvariantCulture).PadLeft(27)
                            + y[i].ToString(CultureInfo.InvariantCulture).PadLeft(27)
                            + z[i].ToString(CultureInfo.InvariantCulture).PadLeft(27);
            switch (ierr)
            {
            case 0:
                Console.WriteLine(cout + eliptc.ToString(CultureInfo.InvariantCulture).PadLeft(27) + "");
                break;

            default:
                Console.WriteLine(cout + "  ***Error***");
                break;
            }
        }
    }
    public static double evaluate(double phi, double a)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    ELLIPTIC_INC_EA evaluates the incomplete elliptic integral E(PHI,A).
    //
    //  Discussion:
    //
    //    The value is computed using Carlson elliptic integrals:
    //
    //      k = sin ( a * Math.PI / 180 )
    //      E(phi,a) =
    //                  sin ( phi )   RF ( cos^2 ( phi ), 1-k^2 sin^2 ( phi ), 1 )
    //        - 1/3 k^2 sin^3 ( phi ) RD ( cos^2 ( phi ), 1-k^2 sin^2 ( phi ), 1 ).
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    25 June 2018
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, double PHI, A, the arguments.
    //    0 <= PHI <= PI/2.
    //    0 <= sin^2 ( A * Math.PI / 180 ) * sin^2(PHI) <= 1.
    //
    //    Output, double ELLIPTIC_INC_EA, the function value.
    //
    {
        int ierr = 0;

        double k = Math.Sin(a * Math.PI / 180.0);

        double       cp     = Math.Cos(phi);
        double       sp     = Math.Sin(phi);
        double       x      = cp * cp;
        double       y      = (1.0 - k * sp) * (1.0 + k * sp);
        const double z      = 1.0;
        const double errtol = 1.0E-03;

        double value1 = Integral.rf(x, y, z, errtol, ref ierr);

        if (ierr != 0)
        {
            Console.WriteLine("");
            Console.WriteLine("ELLIPTIC_INC_EA - Fatal error!");
            Console.WriteLine("  RF returned IERR = " + ierr + "");
            return(1);
        }

        double value2 = Integral.rd(x, y, z, errtol, ref ierr);

        if (ierr != 0)
        {
            Console.WriteLine("");
            Console.WriteLine("ELLIPTIC_INC_EA - Fatal error!");
            Console.WriteLine("  RD returned IERR = " + ierr + "");
            return(1);
        }

        double value = sp * value1 - k * k * sp * sp * sp * value2 / 3.0;

        return(value);
    }
Esempio n. 8
0
 public IntegralDal()
 {
     integral = new Integral();
     except   = new ExceptionHelper();
 }
Esempio n. 9
0
 /// <summary>
 /// 更新比例信息
 /// </summary>
 /// <param name="inte"></param>
 /// <returns></returns>
 public bool UpdateIntegralMessage(Integral inte)
 {
     return(dal.UpdateIntegralMessage(inte));
 }
 private double CoreFunction(double t, double tau)
 {
     return(-Integral.CoefficientForWeakSingular(t, PointsNumber, tau)
            + H(t, tau) * 2.0 * Math.PI
            / (PointsNumber));
 }
Esempio n. 11
0
        private void buttonCalculate_Click(object sender, EventArgs e)
        {
            if (double.TryParse(textBoxA.Text, out double a) && double.TryParse(textBoxB.Text, out a) &&
                double.Parse(textBoxA.Text) < double.Parse(textBoxB.Text) && comboBoxMethods.SelectedIndex > -1)
            {
                List <string> sections      = listBox1.Items.Cast <string>().ToList();
                List <double> times         = new List <double>();
                List <double> parallelTimes = null;
                if (checkBoxParallelMode.Checked)
                {
                    parallelTimes = new List <double>();
                }


                CalculationType currentMethod;
                switch (comboBoxMethods.SelectedIndex)
                {
                case 0: currentMethod = CalculationType.AverageRectangle; break;

                case 1: currentMethod = CalculationType.Trapezium; break;

                case 2: currentMethod = CalculationType.Simpson; break;

                default: MessageBox.Show("Метод не был выбран!"); return;
                }

                IntegralInputParameters inputParameters = new IntegralInputParameters
                {
                    IntegrandExpression = textBoxFunction.Text,
                    StartValue          = int.Parse(textBoxA.Text),
                    EndValue            = int.Parse(textBoxB.Text),
                    ParameterName       = "x"
                };

                Integral currentIntegral = Integral.GetIntegral(currentMethod, inputParameters);

                double    result    = 0.0;
                Stopwatch stopwatch = new Stopwatch();

                foreach (string section in sections)
                {
                    currentIntegral.IterationsNumber = Convert.ToInt32(section);

                    stopwatch.Reset();
                    stopwatch.Start();
                    result = currentIntegral.Calculate();
                    stopwatch.Stop();

                    times.Add(stopwatch.ElapsedMilliseconds / 1000.0);

                    if (checkBoxParallelMode.Checked)
                    {
                        stopwatch.Reset();
                        stopwatch.Start();
                        currentIntegral.CalculateAsync();
                        stopwatch.Stop();

                        parallelTimes.Add(stopwatch.ElapsedMilliseconds / 1000.0);
                    }
                }

                labelResult.Text = $"Результат: {result.ToString()}";

                this.chartResult.Series.Clear();
                this.chartResult.Titles.Clear();

                this.chartResult.Titles.Add("Зависимость времени выполнения от количества разбиений.");

                Series series = this.chartResult.Series.Add("Время выполнения");
                series.ChartType = SeriesChartType.Line;

                for (int i = 0; i < times.Count; i++)
                {
                    series.Points.AddXY(sections[i], times[i]);
                }

                if (checkBoxParallelMode.Checked)
                {
                    Series parallelSeries = this.chartResult.Series.Add("Параллельный вариант");
                    parallelSeries.ChartType = SeriesChartType.Line;

                    for (int i = 0; i < parallelTimes.Count; i++)
                    {
                        parallelSeries.Points.AddXY(sections[i], parallelTimes[i]);
                    }
                }
            }
            else
            {
                MessageBox.Show("Параметры A и B заданы не корректно!");
            }
        }
Esempio n. 12
0
    private static void rj_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    RJ_TEST tests RJ.
    //
    //  Discussion:
    //
    //    This driver tests the function for the
    //    integral Rj(X,Y,Z,P), which is symmetric in X, Y, Z.  The first
    //    twenty sets of values of X, Y, Z, P are extreme points of the region
    //    of valid arguments defined by the machine-dependent constants
    //    LOLIM and UPLIM.  The values of LOLIM, UPLIM, X, Y, Z, P, and
    //    ERRTOL (see comments in void) may be used on most machines
    //    but provide a severe test of robustness only on the ibm 360/370
    //    series.  The twenty-first set tests the failure exit.  The twenty-
    //    second set is a check value:
    //      RJ(2,3,4,5) = 0.1429757966715675383323308.
    //    The remaining sets show the dependence on Z and P
    //    when Y = 1 (no loss of generality because of homogeneity) and
    //    X = 0.5 (midway between the complete case x = 0 and the degenerate
    //    case X = Y).
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 June 2018
    //
    //  Author:
    //
    //    Original FORTRAN77 version by Bille Carlson, Elaine Notis.
    //    C++ version by John Burkardt.
    //
    {
        int i;
        int ierr = 0;

        double[] p =
        {
            2.01E-26,
            2.01E-26,
            2.01E-26,
            2.01E-26,
            2.01E-26,
            2.01E-26,
            2.01E-26,
            2.01E-26,
            2.01E-26,
            2.01E-26,
            2.99E+24,
            2.99E+24,
            2.99E+24,
            2.99E+24,
            2.99E+24,
            2.99E+24,
            2.99E+24,
            2.99E+24,
            2.99E+24,
            2.99E+24,
            1.00E+00,
            5.00E+00,
            0.25E+00,
            0.75E+00,
            1.00E+00,
            2.00E+00,
            0.25E+00,
            0.75E+00,
            1.50E+00,
            4.00E+00,
            0.25E+00,
            0.75E+00,
            3.00E+00,
            1.00E+01,
            0.25E+00,
            0.75E+00,
            5.00E+00,
            2.00E+01,
            0.25E+00,
            0.75E+00,
            5.00E+01,
            2.00E+02
        };

        double[] x =
        {
            1.01E-26,
            1.01E-26,
            0.00E+00,
            0.00E+00,
            0.00E+00,
            2.99E+24,
            0.55E-78,
            0.55E-78,
            0.55E-78,
            2.01E-26,
            1.01E-26,
            1.01E-26,
            0.00E+00,
            0.00E+00,
            0.00E+00,
            2.99E+24,
            0.55E-78,
            0.55E-78,
            0.55E-78,
            2.01E-26,
            0.00E+00,
            2.00E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00
        };

        double[] y =
        {
            1.01E-26,
            1.01E-26,
            2.01E-26,
            2.01E-26,
            2.99E+24,
            2.99E+24,
            2.01E-26,
            2.01E-26,
            2.99E+24,
            2.01E-26,
            1.01E-26,
            1.01E-26,
            2.01E-26,
            2.01E-26,
            2.99E+24,
            2.99E+24,
            2.01E-26,
            2.01E-26,
            2.99E+24,
            2.01E-26,
            1.90E-26,
            3.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00
        };

        double[] z =
        {
            1.01E-26,
            2.99E+24,
            2.01E-26,
            2.99E+24,
            2.99E+24,
            2.99E+24,
            2.01E-26,
            2.99E+24,
            2.99E+24,
            2.01E-26,
            1.01E-26,
            2.99E+24,
            2.01E-26,
            2.99E+24,
            2.99E+24,
            2.99E+24,
            2.01E-26,
            2.99E+24,
            2.99E+24,
            2.01E-26,
            1.90E-26,
            4.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            2.00E+00,
            2.00E+00,
            2.00E+00,
            2.00E+00,
            5.00E+00,
            5.00E+00,
            5.00E+00,
            5.00E+00,
            1.00E+01,
            1.00E+01,
            1.00E+01,
            1.00E+01,
            1.00E+02,
            1.00E+02,
            1.00E+02,
            1.00E+02
        };

        Console.WriteLine("");
        Console.WriteLine("RJ_TEST");
        Console.WriteLine("  RJ evaluates the Carlson elliptic integral");
        Console.WriteLine("  of the third kind, RJ(X,Y,Z,P)");
        Console.WriteLine("");
        Console.WriteLine("               X                          Y" +
                          "                          Z                         P" +
                          "                         RJ(X,Y,Z,P)");
        Console.WriteLine("");

        const double errtol = 1.0E-3;

        for (i = 0; i < 42; i++)
        {
            double eliptc = Integral.rj(x[i], y[i], z[i], p[i], errtol, ref ierr);
            string cout   = x[i].ToString(CultureInfo.InvariantCulture).PadLeft(27)
                            + y[i].ToString(CultureInfo.InvariantCulture).PadLeft(27)
                            + z[i].ToString(CultureInfo.InvariantCulture).PadLeft(27)
                            + p[i].ToString(CultureInfo.InvariantCulture).PadLeft(27);
            switch (ierr)
            {
            case 0:
                Console.WriteLine(cout + eliptc.ToString(CultureInfo.InvariantCulture).PadLeft(27) + "");
                break;

            default:
                Console.WriteLine(cout + "  ***Error***");
                break;
            }
        }
    }
Esempio n. 13
0
    private static void rf_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    RF_TEST tests RF.
    //
    //  Discussion:
    //
    //    This driver tests the function for the
    //    integral RF(X,Y,Z), which is symmetric in X, Y, Z.  The first nine
    //    sets of values of X, Y, Z are extreme points of the region of valid
    //    arguments defined by the machine-dependent constants LOLIM and
    //    UPLIM.  The values of LOLIM, UPLIM, X, Y, Z, and ERRTOL (see
    //    comments in void) may be used on most machines but provide a
    //    severe test of robustness only on the ibm 360/370 series.  The
    //    tenth set tests the failure exit.  The eleventh set is a check
    //    value: RF(0,1,2) = A, where A is the first lemniscate constant.
    //    The remaining sets show the dependence on Z when Y = 1 (no loss of
    //    generality because of homogeneity) and X = 0.5 (midway between the
    //    complete case X = 0 and the degenerate case X = Y).
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 June 2018
    //
    //  Author:
    //
    //    Original FORTRAN77 version by Bille Carlson, Elaine Notis.
    //    C++ version by John Burkardt.
    //
    {
        int i;
        int ierr = 0;

        double[] x =
        {
            1.51E-78,
            1.51E-78,
            0.00E+00,
            0.00E+00,
            0.00E+00,
            0.99E+75,
            0.55E-78,
            0.55E-78,
            0.55E-78,
            0.00E+00,
            0.00E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00,
            0.50E+00
        };

        double[] y =
        {
            1.51E-78,
            1.51E-78,
            3.01E-78,
            3.01E-78,
            0.99E+75,
            0.99E+75,
            3.01E-78,
            3.01E-78,
            0.99E+75,
            2.00E-78,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00
        };

        double[] z =
        {
            1.51E-78,
            0.99E+75,
            3.01E-78,
            0.99E+75,
            0.99E+75,
            0.99E+75,
            3.01E-78,
            0.99E+75,
            0.99E+75,
            1.00E+00,
            2.00E+00,
            1.00E+00,
            1.10E+00,
            1.20E+00,
            1.30E+00,
            1.40E+00,
            1.50E+00,
            1.60E+00,
            1.70E+00,
            1.80E+00,
            1.90E+00,
            2.00E+00,
            2.20E+00,
            2.40E+00,
            2.60E+00,
            2.80E+00,
            3.00E+00,
            3.50E+00,
            4.00E+00,
            4.50E+00,
            5.00E+00,
            6.00E+00,
            7.00E+00,
            8.00E+00,
            9.00E+00,
            1.00E+01,
            2.00E+01,
            3.00E+01,
            4.00E+01,
            5.00E+01,
            1.00E+02,
            2.00E+02,
            5.00E+02,
            1.00E+03,
            1.00E+04,
            1.00E+05,
            1.00E+06,
            1.00E+08,
            1.00E+10,
            1.00E+12,
            1.00E+15,
            1.00E+20,
            1.00E+30,
            1.00E+40,
            1.00E+50
        };

        Console.WriteLine("");
        Console.WriteLine("RF_TEST");
        Console.WriteLine("  RF evaluates the Carlson elliptic integral");
        Console.WriteLine("  of the first kind, RF(X,Y,Z)");
        Console.WriteLine("");
        Console.WriteLine("               X                          Y" +
                          "                          Z                         RF(X,Y,Z)");
        Console.WriteLine(" ");

        const double errtol = 1.0E-3;

        for (i = 0; i < 55; i++)
        {
            string cout = x[i].ToString(CultureInfo.InvariantCulture).PadLeft(27)
                          + y[i].ToString(CultureInfo.InvariantCulture).PadLeft(27)
                          + z[i].ToString(CultureInfo.InvariantCulture).PadLeft(27);
            double eliptc = Integral.rf(x[i], y[i], z[i], errtol, ref ierr);
            switch (ierr)
            {
            case 0:
                Console.WriteLine(cout + " " + eliptc.ToString(CultureInfo.InvariantCulture).PadLeft(27) + "");
                break;

            default:
                Console.WriteLine(cout + "  ***Error***");
                break;
            }
        }
    }
Esempio n. 14
0
    private static void rc_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    RC_TEST tests RC.
    //
    //  Discussion:
    //
    //    This driver tests the function for the
    //    integral RC(X,Y).  The first six sets of values of X and Y are
    //    extreme points of the region of valid arguments defined by the
    //    machine-dependent constants LOLIM and UPLIM.  The values of LOLIM,
    //    UPLIM, X, Y, and ERRTOL (see comments in void) may be used on
    //    most machines but provide a severe test of robustness only on the
    //    ibm 360/370 series.  The seventh set tests the failure exit.  The
    //    next three sets are check values: RC(0,0.25) = RC(0.0625,0.125) = PI
    //    and RC(2.25,2) = LN(2).  The remaining sets show the dependence on X
    //    when Y = 1.  Fixing Y entails no loss here because RC is homogeneous.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 June 2018
    //
    //  Author:
    //
    //    Original FORTRAN77 version by Bille Carlson, Elaine Notis.
    //    C++ version by John Burkardt.
    //
    {
        int i;
        int ierr = 0;

        double[] x =
        {
            1.51E-78,
            3.01E-78,
            0.00E+00,
            0.99E+75,
            0.00E+00,
            0.99E+75,
            0.00E+00,
            0.00E+00,
            6.25E-02,
            2.25E+00,
            0.01E+00,
            0.02E+00,
            0.05E+00,
            0.10E+00,
            0.20E+00,
            0.40E+00,
            0.60E+00,
            0.80E+00,
            1.00E+00,
            1.20E+00,
            1.50E+00,
            2.00E+00,
            3.00E+00,
            4.00E+00,
            5.00E+00,
            1.00E+01,
            2.00E+01,
            5.00E+01,
            1.00E+02,
            1.00E+03,
            1.00E+04,
            1.00E+05,
            1.00E+06,
            1.00E+07,
            1.00E+08,
            1.00E+09,
            1.00E+10,
            1.00E+12,
            1.00E+15,
            1.00E+20,
            1.00E+30,
            1.00E+40,
            1.00E+50
        };

        double[] y =
        {
            1.51E-78,
            0.55E-78,
            3.01E-78,
            0.55E-78,
            0.99E+75,
            0.99E+75,
            2.00E-78,
            2.50E-01,
            1.25E-01,
            2.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00,
            1.00E+00
        };

        Console.WriteLine("");
        Console.WriteLine("RC_TEST");
        Console.WriteLine("  RC evaluates the elementary integral RC(X,Y)");

        Console.WriteLine("");
        Console.WriteLine("              X                          Y                         RC(X,Y)");
        Console.WriteLine("");

        const double errtol = 1.0E-3;

        for (i = 0; i < 43; i++)
        {
            double eliptc = Integral.rc(x[i], y[i], errtol, ref ierr);
            string cout   = "  " + x[i].ToString(CultureInfo.InvariantCulture).PadLeft(27)
                            + "  " + y[i].ToString(CultureInfo.InvariantCulture).PadLeft(27);
            switch (ierr)
            {
            case 0:
                Console.WriteLine(cout + eliptc.ToString(CultureInfo.InvariantCulture).PadLeft(27) + "");
                break;

            default:
                Console.WriteLine("  ***Error***");
                break;
            }
        }
    }
Esempio n. 15
0
        /// <summary>
        /// Determines the integral of a property of the curve over a given interval [startT..endT]
        /// </summary>
        public float GetSegmentIntegral( float startT, float endT, Integral.FunctionDelegate functionToIntegrate )
        {
            if ( ( startT + 1.0f ) <= endT )
            {
                return GaussianQuadrature.Integrate( startT, endT, functionToIntegrate );
            }

            int		startIndex	= ( ( int )startT ) + 1;
            int		endIndex	= ( int )endT;
            float	intStartT	= startIndex;

            float result	= GaussianQuadrature.Integrate( startT, intStartT, functionToIntegrate );

            for ( ; startIndex < endIndex; ++startIndex )
            {
                result += GaussianQuadrature.Integrate( intStartT, intStartT + 1.0f, functionToIntegrate );
                ++intStartT;
            }

            result += GaussianQuadrature.Integrate( endIndex, endT, functionToIntegrate );

            return result;
        }
Esempio n. 16
0
    private static void hermite_polynomial_test07()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    HERMITE_POLYNOMIAL_TEST07 tests HE_QUADRATURE_RULE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    08 March 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int e;

        double[] f;
        int      i;
        int      n;
        double   q;
        double   q_exact;

        double[] w;
        double[] x;

        Console.WriteLine("");
        Console.WriteLine("HERMITE_POLYNOMIAL_TEST07:");
        Console.WriteLine("  HE_QUADRATURE_RULE computes the quadrature rule");
        Console.WriteLine("  associated with He(n,x)");

        n = 7;
        x = new double[n];
        w = new double[n];

        HermiteQuadrature.he_quadrature_rule(n, ref x, ref w);

        typeMethods.r8vec2_print(n, x, w, "      X            W");

        Console.WriteLine("");
        Console.WriteLine("  Use the quadrature rule to estimate:");
        Console.WriteLine("");
        Console.WriteLine("    Q = Integral ( -oo < X < +00 ) X^E exp(-X^2) dx");
        Console.WriteLine("");
        Console.WriteLine("   E       Q_Estimate      Q_Exact");
        Console.WriteLine("");

        f = new double[n];

        for (e = 0; e <= 2 * n - 1; e++)
        {
            switch (e)
            {
            case 0:
            {
                for (i = 0; i < n; i++)
                {
                    f[i] = 1.0;
                }

                break;
            }

            default:
            {
                for (i = 0; i < n; i++)
                {
                    f[i] = Math.Pow(x[i], e);
                }

                break;
            }
            }

            q       = typeMethods.r8vec_dot_product(n, w, f);
            q_exact = Integral.he_integral(e);
            Console.WriteLine("  " + e.ToString().PadLeft(2)
                              + "  " + q.ToString().PadLeft(14)
                              + "  " + q_exact.ToString().PadLeft(14) + "");
        }
    }
Esempio n. 17
0
    private static void test02()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST02 tests Padua rules for the Legendre 2D integral.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    31 May 2014
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double[] a = new double[2];
        double[] b = new double[2];
        int      l;

        a[0] = -1.0;
        a[1] = -1.0;
        b[0] = +1.0;
        b[1] = +1.0;

        Console.WriteLine("");
        Console.WriteLine("TEST02");
        Console.WriteLine("  Padua rule for the 2D Legendre integral.");
        Console.WriteLine("  Density function rho(x) = 1.");
        Console.WriteLine("  Region: -1 <= x <= +1.");
        Console.WriteLine("  Region: -1 <= y <= +1.");
        Console.WriteLine("  Level: L");
        Console.WriteLine("  Exactness: L+1 when L is 0,");
        Console.WriteLine("             L   otherwise.");
        Console.WriteLine("  Order: N = (L+1)*(L+2)/2");

        for (l = 0; l <= 5; l++)
        {
            int n = (l + 1) * (l + 2) / 2;

            double[] w = new double[n];
            double[] x = new double[n];
            double[] y = new double[n];

            Burkardt.Values.Padua.padua_point_set(l, ref x, ref y);
            Burkardt.Values.Padua.padua_weight_set(l, ref w);

            int p_max = l switch
            {
                0 => l + 2,
                _ => l + 1
            };

            Integral.legendre_2d_exactness(a, b, n, ref x, ref y, ref w, p_max);
        }
    }
}
Esempio n. 18
0
        private void btCalc_Click(object sender, EventArgs e)
        {
            rtbLog.Clear();

            double[] koefSin = new double[100];
            double[] koefPar = new double[100];
            double   time, time1, time2, time8;

            double[] time3 = new double[4];
            double[] time4 = new double[100];
            double[] time5 = new double[100];
            double[] time6 = new double[100];
            double[] time7 = new double[100];

            double   a    = Convert.ToDouble(tbA.Text);
            double   b    = Convert.ToDouble(tbB.Text);
            long     N    = Convert.ToInt64(nudN.Text);
            Integral aInt = new Integral(a, b, N, SumIntegral);

            double result  = aInt.Rectangle(out time, ref time4);
            double result1 = aInt.RectangleThreadParralel(out time1, ref time3, ref time5);
            double result2 = aInt.RectangleForParralel(out time2);
            double result3 = aInt.RectangleTaskParralel(out time8);

            rtbLog.AppendText("Последовательный вариант" + Environment.NewLine);
            rtbLog.AppendText("Ответ: " + result.ToString() + Environment.NewLine);
            rtbLog.AppendText("Время: " + time.ToString() + Environment.NewLine);

            rtbLog.AppendText("Parallel Threads вариант" + Environment.NewLine);
            rtbLog.AppendText("Ответ: " + result1.ToString() + Environment.NewLine);
            rtbLog.AppendText("Время: " + time3[0].ToString() + Environment.NewLine);

            rtbLog.AppendText("Parallel For вариант" + Environment.NewLine);
            rtbLog.AppendText("Ответ: " + result2.ToString() + Environment.NewLine);
            rtbLog.AppendText("Время: " + time2.ToString() + Environment.NewLine);

            rtbLog.AppendText("Parallel Tasks вариант" + Environment.NewLine);
            rtbLog.AppendText("Ответ: " + result3.ToString() + Environment.NewLine);
            rtbLog.AppendText("Время: " + time8.ToString() + Environment.NewLine);

            rtbLog.AppendText(Environment.NewLine);

            for (int i = 0; i < 3; i++)
            {
                chart3.Series[i].Points.Clear();
            }

            chart2.Series[0].Points.Clear();
            chart1.Series[0].Points.Clear();
            chart1.Series[1].Points.Clear();
            chart4.Series[0].Points.Clear();
            chart4.Series[1].Points.Clear();

            chart3.Series[0].Points.AddXY(1, time);
            chart3.Series[1].Points.AddXY(2, time3[0]);
            chart3.Series[2].Points.AddXY(3, time2);

            chart2.Series[0].Points.AddXY(1, time);
            chart2.Series[0].Points.AddXY(2, time3[1]);
            chart2.Series[0].Points.AddXY(3, time3[2]);
            chart2.Series[0].Points.AddXY(4, time3[0]);

            time6[0] = time4[99];
            time7[0] = time5[99];

            for (int i = 0; i < 98; i++)
            {
                koefSin[97 - i] = time4[i + 2] / time4[i + 1];
                koefPar[97 - i] = time5[i + 2] / time5[i + 1];
                time6[i + 1]    = time6[i] / koefSin[97 - i];
                time7[i + 1]    = time7[i] / koefPar[97 - i];

                chart1.Series[0].Points.AddXY(i * N / 100, time4[i]);
                chart1.Series[1].Points.AddXY(i * N / 100, time5[i]);
                chart4.Series[0].Points.AddXY(i * (b - a) / 100, time6[i]);
                chart4.Series[1].Points.AddXY(i * (b - a) / 100, time7[i]);
            }
        }
Esempio n. 19
0
 public IntegralThread(Integral calka, int xp, int xk)
 {
     this.calka = calka;
     this.xp    = xp;
     this.xk    = xk;
 }
Esempio n. 20
0
        private AddToTree.Tree Solver()
        {
            UknownIntegralSolver UNKNOWN = this;

            this.SetProgressValue(progressBar1, 0);

            int INCREASE = 2147483647 / 10;

            this.SetProgressValue(progressBar1, this.progressBar1.Value + INCREASE);


            //ERRORCUASE1715 :ERRROR cause of ERROR317142.the copy operation is not valid.
            //ERROR3175 :Error in data structure .
            //ERRORCAUSE0981243  ;The cause ERROR3175 of  is at here.Error on copy tree.refer to page 177.
            if (Enterface.SenderAccess.AutoSenderAccess.NodeAccess.SampleAccess == null && Enterface.SenderAccess.AutoSenderAccess != null)
            {
                Enterface.SenderAccess.AutoSenderAccess.NodeAccess = new AddToTree.Tree(Enterface.SenderAccess.AutoSenderAccess.CurrentStirngAccess, false);
            }
            AddToTree.Tree Copy = Enterface.SenderAccess.AutoSenderAccess.NodeAccess.CopyNewTree(Enterface.SenderAccess.AutoSenderAccess.NodeAccess);
            //Copy = TransmisionToDeleteingMinusPluse.TrasmisionToDeleteingMinusPluseFx(Copy);
            //ERROR918243 :The error at splitation.refer to page 176.
            //Copy = TransmisionToDeleteingMinusPluse.TrasmisionToDeleteingMinusPluseFx(Copy);

            AddToTree.Tree CopyNode = null;
            CopyNode = Copy.CopyNewTree(Copy);
            this.SetProgressValue(progressBar1, this.progressBar1.Value + INCREASE);

            Copy = DeleteingMinusPluseTree.DeleteingMinusPluseFx(Copy);

            this.SetProgressValue(progressBar1, this.progressBar1.Value + INCREASE);

            Copy = Spliter.SpliterFx(Copy, ref UNKNOWN);

            this.SetProgressValue(progressBar1, this.progressBar1.Value + INCREASE);

            Copy = Simplifier.ArrangmentForSpliter(Copy);
            //ERROR30175541  :SIMPLIFIER HAS CUASED TO SOME ERRRO.refer to page 176.
            //ERROR312317 & ERRROR317140 :Error in simplification.refer to page 182.

            this.SetProgressValue(progressBar1, this.progressBar1.Value + INCREASE);

            //Copy = Simplifier.SimplifierFx(Copy,ref UNKNOWN);
            //ERROR30174213  :The Simplified is invalid here.refer to page 180.
            //Copy = Derivasion.DerivasionOfFX(Copy);

            this.SetProgressValue(progressBar1, this.progressBar1.Value + INCREASE);

            Copy = Integral.IntegralOfFX(Copy, ref UNKNOWN);

            /*int i = 0;
             * while (true)new AddToTree.Tree(null, false);
             * {
             *  //Copy = Integral.DervisionI(i, Copy);
             *  //ERROR981273987 :The error at derivation.refer to page 205.
             *   Copy = Derivasion.DerivasionOfFX(Copy);
             *  //ERROR3017181920 :refer to page 188.
             *
             *  Copy=Simplifier.SimplifierFx(Copy);
             *  i++;
             * }
             */

            //LOCATION13174253. refer to page 208.
            //ERROR3070405060 :The error is here.refer to page 220.
            //int NUM1 = Integral.NumberOfElements(Copy);
            this.SetProgressValue(progressBar1, this.progressBar1.Value + INCREASE);

            int NUM1 = Integral.NumberOfElements(Copy);

            this.SetProgressValue(progressBar1, this.progressBar1.Value + INCREASE);

            Copy = Simplifier.SimplifierFx(Copy, ref UNKNOWN);

            this.SetProgressValue(progressBar1, this.progressBar1.Value + INCREASE);

            int NUM2 = Integral.NumberOfElements(Copy);

            this.SetProgressValue(progressBar1, this.progressBar1.Value + INCREASE);

            //Copy = RoundTree.RoundTreeMethod(Copy,0);

            Copy.ThreadAccess = null;
            Thread t = new Thread(new ThreadStart(Verifing));

            t.Start();
            //ERRORCORECTION6646464654643211:The Verification Return Valid result:1394/4/9
            if (EqualToObject.IsEqualWithOutThreadConsiderationCommonly(Simplifier.SimplifierFx(RoundTree.RoundTreeMethod(ChangeFunction.ChangeFunctionFx(Derivasion.DerivasionOfFX(Copy.CopyNewTree(Copy), ref UNKNOWN), ref UNKNOWN), RoundTree.MaxFractionalDesimal(CopyNode)), ref UNKNOWN), CopyNode))
            {
                t.Abort();
                SetLableValue(label17, "Verifing finished.Integral Answer Calculated is :");
                MessageBox.Show("Verify OK");
            }
            else
            {
                t.Abort();
                SetLableValue(label17, "Verifing finished.Integral Answer Calculated is :");
                MessageBox.Show("Verify Failed.");
            }

            return(Copy);

            //this.SetProgressValue(progressBar1, this.progressBar1.Value + INCREASE);
        }
Esempio n. 21
0
    public static double monomial_quadrature_jacobi(int expon, double alpha, double beta,
                                                    int order, double[] w, double[] x)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MONOMIAL_QUADRATURE_JACOBI applies a quadrature rule to a monomial.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    22 January 2008
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int EXPON, the exponent.
    //
    //    Input, double ALPHA, the exponent of (1-X) in the weight factor.
    //
    //    Input, double BETA, the exponent of (1+X) in the weight factor.
    //
    //    Input, int ORDER, the number of points in the rule.
    //
    //    Input, double W[ORDER], the quadrature weights.
    //
    //    Input, double X[ORDER], the quadrature points.
    //
    //    Output, double MONOMIAL_QUADRATURE_JACOBI, the quadrature error.
    //
    {
        int i;
        //
        //  Get the exact value of the integral of the unscaled monomial.
        //
        double exact = Integral.jacobi_integral(expon, alpha, beta);
        //
        //  Evaluate the unweighted monomial at the quadrature points.
        //
        double quad = 0.0;

        for (i = 0; i < order; i++)
        {
            quad += w[i] * Math.Pow(x[i], expon);
        }

        double quad_error = exact switch
        {
            //
            //  Absolute error for cases where exact integral is zero,
            //  Relative error otherwise.
            //
            0.0 => Math.Abs(quad),
            _ => Math.Abs(quad - exact) / Math.Abs(exact)
        };

        return(quad_error);
    }
Esempio n. 22
0
 /// <summary>
 /// Length of curve f(x) from x=a to x=b.
 /// </summary>
 /// <param name="f">The function f(x).</param>
 /// <param name="a">The starting point a.</param>
 /// <param name="b">The ending point b.</param>
 /// <param name="intMethod">The integration method.</param>
 /// <param name="n">The n.</param>
 /// <param name="diffMethod">The differation method.</param>
 public static double CurveLength(Function f, double a, double b, Integral intMethod, int n, Differentiation diffMethod)
 {
     return(intMethod((double x) => Math.Sqrt(1 + Math.Pow(diffMethod(f, x), 2)), a, b, n));
 }
Esempio n. 23
0
    private static void rc_test2()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    RC_TEST2 checks RC by examining special values.
    //
    //  Discussion:
    //
    //    This driver compares values of (LOG X)/(X-1) and ARCTAN(X)
    //    calculated on one hand from the void RC and on the other
    //    from library LOG and ARCTAN routines.  to avoid over/underflows
    //    for extreme values of X, we write (LOG X)/(X-1) = RC(Y,X/Y)/SQRT(Y),
    //    where Y = (1+X)/2, and ARCTAN(X) = SQRT(X)*RC(Z,Z+X), where Z = 1/X.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 June 2018
    //
    //  Author:
    //
    //    Original FORTRAN77 version by Bille Carlson, Elaine Notis.
    //    C++ version by John Burkardt.
    //
    {
        int    i;
        double ibmlog;
        int    ierr = 0;
        int    j;
        int    m;
        double mylog;
        double v;
        double x;

        double[] x_vec =
        {
            1.0E-75,
            1.0E-15,
            1.0E-03,
            1.0E-01,
            2.0E-01,
            5.0E-01,
            1.0E+00,
            2.0E+00,
            5.0E+00,
            1.0E+01,
            1.0E+03,
            1.0E+15,
            1.0E+75
        };
        double y;

        Console.WriteLine("");
        Console.WriteLine("RC_TEST2");
        Console.WriteLine("  Compare LOG(X)/(X-1) and ARCTAN(X) with");
        Console.WriteLine("  values based on RC.");

        Console.WriteLine("");
        Console.WriteLine("     X                From LOG                   From RC");
        Console.WriteLine("");

        const double errtol = 1.0E-3;

        for (j = 1; j <= 10; j++)
        {
            string cout = "";
            x     = 0.2 * j;
            y     = (1.0 + x) / 2.0;
            v     = x / y;
            mylog = Integral.rc(y, v, errtol, ref ierr) / Math.Sqrt(y);
            cout  = x.ToString("0.#").PadLeft(9) + "     ";
            switch (j)
            {
            case 5:
                cout = "**** ZERO DIVIDE *****";
                break;

            default:
                ibmlog = Math.Log(x) / (x - 1.0);
                cout  += ibmlog.ToString("0.################").PadLeft(27);
                break;
            }

            Console.WriteLine(cout + mylog.ToString("0.################").PadLeft(27) + "");
        }

        Console.WriteLine("");
        Console.WriteLine("  Extreme values of X");
        Console.WriteLine("");
        Console.WriteLine("     X                From LOG                   From RC");
        Console.WriteLine("");

        for (i = 0; i < 16; i++)
        {
            int ipower = -75 + 10 * i;
            x      = Math.Pow(10.0, ipower);
            y      = (1.0 + x) / 2.0;
            v      = x / y;
            mylog  = Integral.rc(y, v, errtol, ref ierr) / Math.Sqrt(y);
            ibmlog = Math.Log(x) / (x - 1.0);
            Console.WriteLine(x.ToString("0.#").PadLeft(8)
                              + ibmlog.ToString("0.################").PadLeft(27)
                              + mylog.ToString("0.################").PadLeft(27) + "");
        }

        Console.WriteLine("");
        Console.WriteLine("     X              From ARCTAN                 From RC");
        Console.WriteLine("");

        for (m = 0; m < 13; m++)
        {
            x = x_vec[m];
            double z      = 1.0 / x;
            double w      = z + x;
            double myarc  = Math.Sqrt(x) * Integral.rc(z, w, errtol, ref ierr);
            double ibmarc = Math.Atan(x);
            Console.WriteLine(x.ToString("0.#").PadLeft(8)
                              + ibmarc.ToString("0.################").PadLeft(27)
                              + myarc.ToString("0.################").PadLeft(27) + "");
        }
    }