Ejemplo n.º 1
0
        public static List <double> RungeKut(Math.Interval interval, FuncDiff func, double y0)
        {
            if (!interval.isValid)
            {
                return(null);
            }

            double        deltaY, yNext, yPrev;
            List <double> result = new List <double>();

            yPrev = y0;
            double k1, k2, k3, k4;

            foreach (double x in interval.Points)
            {
                k1      = interval.Step * func(x, y0);
                k2      = interval.Step * func(x + (interval.Step / 2), y0 + (k1 / 2));
                k3      = interval.Step * func(x + (interval.Step / 2), y0 + (k2 / 2));
                k4      = interval.Step * func(x + interval.Step, y0 + k3);
                deltaY  = (k1 + 2 * k2 + 2 * k3 + k4);
                deltaY /= 6;

                yNext = y0 + deltaY;
                result.Add(y0);
                y0 = yNext;
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static double Simpson(Func func, Math.Interval interval)
        {
            if (!interval.isValid)
            {
                return(double.NaN);
            }

            if (interval.PointsCount % 2 == 0)
            {
                interval.PointsCount += 1;
            }
            double        result = func(interval.A) + func(interval.B);
            List <double> x      = interval.Points;

            double tmp1 = 0;
            double tmp2 = 0;

            for (int i = 1; i < x.Count - 1; i++)
            {
                if (i % 2 != 0)
                {
                    tmp1 += func(x[i]);
                }
                else
                {
                    tmp2 += func(x[i]);
                }
            }
            result += 4 * tmp1 + 2 * tmp2;

            return(result * interval.Step / 3);
        }
Ejemplo n.º 3
0
        public static double Iteration(Func polynom, Func dx, Math.Interval interval, double accuracy)
        {
            double xk = interval.A;
            double x;
            double dxMin, dxMax;
            double lyambda;

            dxMin = dxMax = dx(interval.A);
            for (double i = interval.A; i < interval.B; i += accuracy)
            {
                if (dxMin > dx(i))
                {
                    dxMin = dx(i);
                }

                if (dxMax < dx(i))
                {
                    dxMax = dx(i);
                }
            }
            if (dxMax <= 3 * dxMin)
            {
                lyambda = 1.25 / dxMax;
            }
            else
            {
                lyambda = 1 / dxMax;
            }
            do
            {
                x  = xk;
                xk = x - lyambda * polynom(x);
            }while (Math.Abs(x - xk) >= accuracy);
            return(xk);
        }
Ejemplo n.º 4
0
        public static List <double> EilerPlus(ref Math.Interval interval, FuncDiff func, double y0)
        {
            if (!interval.isValid)
            {
                return(null);
            }

            double        deltaY, yNext, yPrev;
            List <double> result = new List <double>();

            yPrev = y0;
            bool parity = true;

            interval.PointsCount = interval.PointsCount * 2 - 1;
            foreach (double x in interval.Points)
            {
                if (parity)
                {
                    deltaY = interval.Step * func(x, y0);
                    yNext  = y0 + deltaY;
                }
                else
                {
                    deltaY = 2 * interval.Step * func(x, y0);
                    yNext  = yPrev + deltaY;
                }

                result.Add(y0);
                yPrev  = y0;
                y0     = yNext;
                parity = !parity;
            }

            return(result);
        }
Ejemplo n.º 5
0
 private void DrawChart(Math.Interval interval, double step)
 {
     if (!interval.isValid)
     {
         return;
     }
     chPolindrome.Series[0].Points.Clear();
     for (double i = interval.A; i <= interval.B + step; i += step)
     {
         chPolindrome.Series[0].Points.AddXY(i, Polindrome(i));
     }
 }
Ejemplo n.º 6
0
 public Form1()
 {
     InitializeComponent();
     chartInterval       = new Math.Interval(-2, 2);
     rootInterval        = new Math.Interval(-2, 2);
     tbA.Text            = (-2).ToString();
     tbB.Text            = (2).ToString();
     tbRootA.Text        = (-2).ToString();
     tbRootB.Text        = (2).ToString();
     rootAccuracy        = 0.001;
     tbRootAccuracy.Text = rootAccuracy.ToString();
 }
Ejemplo n.º 7
0
        public static double Rectangle(Func func, Math.Interval interval)
        {
            if (!interval.isValid)
            {
                return(double.NaN);
            }

            double        result = 0;
            List <double> x      = interval.Points;

            for (int i = 0; i < x.Count - 1; i++)
            {
                result += func(x[i] + interval.Step * 0.5);
            }

            return(result * interval.Step);
        }
Ejemplo n.º 8
0
        public static double Trapezoid(Func func, Math.Interval interval)
        {
            if (!interval.isValid)
            {
                return(double.NaN);
            }

            double        result = (func(interval.A) + func(interval.B)) / 2;
            List <double> x      = interval.Points;

            for (int i = 1; i < x.Count - 1; i++)
            {
                result += func(x[i]);
            }

            return(result * interval.Step);
        }
Ejemplo n.º 9
0
        public static List <double> Eiler(Math.Interval interval, FuncDiff func, double y0)
        {
            if (!interval.isValid)
            {
                return(null);
            }

            double        deltaY, yNext;
            List <double> result = new List <double>();

            foreach (double x in interval.Points)
            {
                deltaY = interval.Step * func(x, y0);
                yNext  = y0 + deltaY;
                result.Add(y0);
                y0 = yNext;
            }

            return(result);
        }
Ejemplo n.º 10
0
 public bool Verification(Func polynom, Math.Interval interval, Label tbResult)
 {
     if (polynom(interval.A) == 0)
     {
         tbResult.Text = interval.A.ToString();
         return(false);
     }
     if (polynom(interval.B) == 0)
     {
         tbResult.Text = interval.B.ToString();
         return(false);
     }
     if (polynom(interval.A) * polynom(interval.B) > 0)
     {
         tbResult.Text = "Нет корня";
         return(false);
     }
     if (!interval.isValid)
     {
         tbResult.Text = "Неверно указан интервал";
         return(false);
     }
     return(true);
 }
Ejemplo n.º 11
0
        private void pbEilerPlus_Click(object sender, EventArgs e)
        {
            Math.Interval interval = ReadParametrs();
            if (!interval.isValid)
            {
                return;
            }

            double y0;

            if (!double.TryParse(tbY0.Text, out y0))
            {
                MessageBox.Show("Неверно указана начальная точка");
            }

            List <double> solution = DiffEq.EilerPlus(ref interval, DiffEqFunc, y0);

            if (solution == null)
            {
                MessageBox.Show("Произошла ошибка");
            }

            FillDGV(interval.Points, solution, dgvResult);
        }
Ejemplo n.º 12
0
        public static double Dichotomy(Func polynom, Math.Interval interval, double accuracy)
        {
            double root, funcVal;

            do
            {
                root    = (interval.A + interval.B) / 2;
                funcVal = polynom(root);
                if (funcVal == 0)
                {
                    break;
                }
                if (polynom(interval.A) * funcVal < 0)
                {
                    interval.B = root;
                }
                else
                {
                    interval.A = root;
                }
            } while (Math.Abs(interval.A - interval.B) >= accuracy);

            return(root);
        }
Ejemplo n.º 13
0
        public static double Tangent(Func polynom, Func dx, Func d2x, Math.Interval interval, double accuracy)
        {
            double point, root;

            if (polynom(interval.A) * d2x(interval.A) > 0)
            {
                do
                {
                    point      = interval.A;
                    interval.A = point - polynom(point) / dx(point);
                    root       = interval.A;
                }while (Math.Abs(interval.A - point) >= accuracy);
            }
            else
            {
                do
                {
                    point      = interval.B;
                    interval.B = point - polynom(point) / dx(point);
                    root       = interval.B;
                }while (Math.Abs(interval.B - point) >= accuracy);
            }
            return(root);
        }
Ejemplo n.º 14
0
        public static double Hords(Func polynom, Func d2x, Math.Interval interval, double accuracy)
        {
            double border, root;

            if (d2x(interval.A) * polynom(interval.A) > 0)
            {
                do
                {
                    border     = interval.B;
                    interval.B = interval.B - ((interval.B - interval.A) * polynom(interval.B)) / (polynom(interval.B) - polynom(interval.A));
                    root       = interval.B;
                } while (Math.Abs(interval.B - border) >= accuracy);
            }
            else
            {
                do
                {
                    border     = interval.A;
                    interval.A = interval.A - ((interval.B - interval.A) * polynom(interval.A)) / (polynom(interval.B) - polynom(interval.A));
                    root       = interval.A;
                } while (Math.Abs(interval.A - border) >= accuracy);
            }
            return(root);
        }