示例#1
0
        //INtegration of 3/4/8 point area
        private void Integrate2D_Click(object sender, EventArgs e)
        {
            int m = 3;

            if (comboBox3.SelectedIndex == 1)
            {
                m = 4;
            }
            if (comboBox3.SelectedIndex == 2)
            {
                m = 8;
            }

            double [][] pi = new double[m][];

            for (int i = 0; i < m; i++)
            {
                pi[i] = new double[2];
            }

            if (!ValidateAreaPoints(pi))
            {
                return;
            }

            try
            {
                var funstr = textBox4.Text;
                function = context.CompileGeneric <double>(funstr);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in fun definition. ERROR: " + ex.Message);
                label5.Text = "I=n/a";
                return;
            }

            int gp = 0;

            if (int.TryParse(cmbGPoints.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out gp) != true)
            {
                MessageBox.Show("Invalid number of Gaussian points!");
                label11.Text = "";
                return;
            }

            double retVal = 0;

            if (comboBox3.SelectedIndex == 0)
            {
                retVal = GaussIntegrator.Calculate2DIntegral_Triangle(function, register, gp, pi);
            }
            else
            {
                retVal = GaussIntegrator.Calculate2DIntegral_Quadrilateral(function, register, gp, pi);
            }


            label11.Text = string.Format("I={0:0.0000000000}", retVal);
        }
        /// <summary>
        /// Compute the n-th stage integral.
        /// </summary>
        /// <param name="n"> Number of steps. </param>
        /// <returns> the value of n-th stage integral. </returns>
        /// <exception cref="TooManyEvaluationsException"> if the maximum number of evaluations
        /// is exceeded. </exception>
        private double Stage(int n)
        {
            // Function to be integrated is stored in the base class.
            UnivariateFunction f = new UnivariateFunctionAnonymousInnerClassHelper(this);

            double min  = this.Min;
            double max  = this.Max;
            double step = (max - min) / n;

            double sum = 0;

            for (int i = 0; i < n; i++)
            {
                // Integrate over each sub-interval [a, b].
                double          a = min + i * step;
                double          b = a + step;
                GaussIntegrator g = FACTORY.Legendre(this.numberOfPoints, a, b);
#if false
                GaussIntegrator g = FACTORY.LegendreHighPrecision(this.numberOfPoints, a, b);
#endif
                sum += g.Integrate(f);
            }

            return(sum);
        }
示例#3
0
        /// <summary>
        /// Perform integration
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Integrate1D_Click(object sender, EventArgs e)
        {
            double a = 0, b = 0;
            int    n = 2;

            if (double.TryParse(textBox1.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out a) != true)
            {
                MessageBox.Show("First point \"a\" of interval is invalid!");
                label5.Text = "";
                return;
            }

            if (double.TryParse(textBox2.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out b) != true)
            {
                MessageBox.Show("Second point \"b\" of interval is invalid!");
                label5.Text = "";
                return;
            }

            if (int.TryParse(comboBox4.Text, NumberStyles.None, CultureInfo.InvariantCulture, out n) != true)
            {
                MessageBox.Show("Number of points is invalid!");
                label5.Text = "";
                return;
            }

            if (n > 64)
            {
                MessageBox.Show("Number of points must be less than 65!");
                label5.Text = "";
                return;
            }

            try
            {
                var funstr = textFunction.Text;
                function = context.CompileGeneric <double>(funstr);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in fun definition. ERROR: " + ex.Message);
                label5.Text = "I=n/a";
                return;
            }

            double[][] pi = new double[2][];
            pi[0]    = new double[2];
            pi[1]    = new double[2];
            pi[0][0] = a;
            pi[1][0] = b;

            //perform integration
            double retVal = GaussIntegrator.Calculate1DIntegral(function, register, n, pi);

            label5.Text = string.Format("I={0:0.0000000000}", retVal);
        }