private double SumForIntegralApproximation(MathFunction func, double a, double b, double[] solutions, double[] coefs)
        {
            double result = 0;

            for (int i = 0; i <= powerForCoefCalculation; i++)
            {
                double x = (a + b) / 2 + (b - a) / 2 * solutions[i];
                result += coefs[i] * func.Calculate(x);
            }

            result *= (b - a) / 2;

            return(result);
        }
        public double Solve(MathFunction func, double a, double b, int n)
        {
            if (a == b)
            {
                return(0);
            }
            if (a > b)
            {
                double tmp = a; a = b; b = tmp;
            }

            double result     = 0;
            double difference = (b - a) / n;

            for (int i = 1; i < n; i++)
            {
                result += func.Calculate(a + difference * i);
            }
            result += (func.Calculate(a) + func.Calculate(b)) / 2;
            result *= difference;

            return(result);
        }
示例#3
0
        public double Solve(MathFunction func, double a, double b, int n)
        {
            if (a == b)
            {
                return(0);
            }
            if (a > b)
            {
                double tmp = a; a = b; b = tmp;
            }

            double result     = 0;
            double difference = (b - a) / (2 * n);

            for (int k = 1; k < n; k++)
            {
                result += 4 * func.Calculate(a + difference * (2 * k - 1));
                result += 2 * func.Calculate(a + difference * 2 * k);
            }
            result += 4 * func.Calculate(b - difference) + func.Calculate(a) + func.Calculate(b);
            result *= difference / 3;

            return(result);
        }
        public double Solve(MathFunction func, double a, double b, int n)
        {
            if (a == b)
            {
                return(0);
            }
            if (a > b)
            {
                double tmp = a;
                a = b; b = tmp;
            }

            double result     = 0;
            double difference = (b - a) / n;

            for (int i = 0; i < n; i++)
            {
                result += func.Calculate(SuitableXForIndex(a + difference * i, a + difference * (i + 1)));
            }
            result *= difference;

            return(result);
        }
示例#5
0
        public GraphicsPath PathForSimpsonMethod(MathFunction func, double a, double b, int n)
        {
            GraphicsPath path = new GraphicsPath();

            double difference = (b - a) / n;

            for (int i = 0; i < n; i++)
            {
                double       x           = a + difference * i;
                MathFunction simpsonFunc = FunctionForSimpsonInterval(new PointF((float)x, (float)func.Calculate(x)),
                                                                      new PointF((float)(x + difference / 2), (float)func.Calculate(x + difference / 2)),
                                                                      new PointF((float)(x + difference), (float)func.Calculate(x + difference)));
                path.AddPath(PathForFunction(simpsonFunc, x, x + difference), false);
            }

            return(path);
        }
示例#6
0
        public GraphicsPath PathForFunction(MathFunction func, double a, double b)
        {
            GraphicsPath path = new GraphicsPath();

            path.StartFigure();
            path.AddLines(PointsForFunction(func, a, b));

            path.AddLine(new PointF((float)FunctionXToScreenX(b), (float)FunctionYToScreenY(func.Calculate(b))),
                         new PointF((float)FunctionXToScreenX(b), (float)FunctionYToScreenY(0)));
            path.AddLine(new PointF((float)FunctionXToScreenX(b), (float)FunctionYToScreenY(0)),
                         new PointF((float)FunctionXToScreenX(a), (float)FunctionYToScreenY(0)));
            path.CloseFigure();

            return(path);
        }
示例#7
0
        private PointF[] PointsForFunction(MathFunction func, double a, double b)
        {
            int count = Convert.ToInt32((b - a) / epsilan) + 1;

            PointF[] points = new PointF[Convert.ToInt32((b - a) / epsilan) + 1];
            for (int i = 0; i < count; i++)
            {
                points[i] = new PointF((float)FunctionXToScreenX(a + i * epsilan), (float)FunctionYToScreenY(func.Calculate(a + i * epsilan)));
            }

            return(points);
        }