예제 #1
0
파일: Form2.cs 프로젝트: a-27m/vssdb
        private void buttonTaylor_Click(object sender, EventArgs e)
        {
            try
            {
                a = float.Parse(textBoxA.Text);
                b = float.Parse(textBoxB.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Parsing error, aborted.");
                return;
            }

            DekartForm df = new DekartForm(150, 150, 50, 430);

            df.Size = new Size(440, 540);
            df.Text = "Red - error | Olive - Taylor's row | Green - f(x)";

            df.AddGraphic(new DoubleFunction(taylor_err), a, b, DrawModes.DrawLines,
                          Color.Red);
            df.AddGraphic(new DoubleFunction(taylor), a, b, DrawModes.DrawLines,
                          Color.Olive);
            df.AddGraphic(new DoubleFunction(f), a, b, DrawModes.DrawPoints,
                          Color.Green);
            //df.DrawAllGraphics();
            df.Show();
        }
예제 #2
0
        private void tool_f_Click(object sender, EventArgs e)
        {
            try
            {
                a = float.Parse(textBoxA.Text);
                b = float.Parse(textBoxB.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Parsing error, aborted.");
                return;
            }

            if ((!checkBoxReuse.Checked) || (dForm == null))
            {
                dForm      = new DekartForm(100, 100, 50, 400);
                dForm.Size = new Size(440, 540);
            }
            else
            {
                dForm.RemoveAllGraphics();
            }

            dForm.Text = "Green - f(x)";
            dForm.AddGraphic(new DoubleFunction(f), a, b, DrawModes.DrawLines,
                             Color.Green);
            dForm.Show();
        }
예제 #3
0
파일: Form2.cs 프로젝트: a-27m/vssdb
        private void buttonTask1_Click(object sender, EventArgs e)
        {
            try
            {
                a = float.Parse(textBoxA.Text);
                b = float.Parse(textBoxB.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Parsing error, aborted.");
                return;
            }

            DekartForm df = new DekartForm(40, 40,
                                           Screen.PrimaryScreen.WorkingArea.Width / 2,
                                           Screen.PrimaryScreen.WorkingArea.Height / 2);

            df.WindowState = FormWindowState.Maximized;
            df.Text        = "Red - f(x) | Olive - df(x)/dx | Green - d²f(x)/dx²";

            df.AddGraphic(new DoubleFunction(f), a, b, DrawModes.DrawLines,
                          Color.Red);
            df.AddGraphic(new DoubleFunction(deriv_f), a, b, DrawModes.DrawLines,
                          Color.Olive);
            df.AddGraphic(new DoubleFunction(deriv2_f), a, b, DrawModes.DrawLines,
                          Color.Green);
            df.Show();
            //DrawAllGraphics();
        }
예제 #4
0
        private void buttonSysFailPeriodic_Click(object sender, EventArgs e)
        {
            if (ActiveMdiChild is FormChild)
            {
                FormChild activeMdiChild = ActiveMdiChild as FormChild;

                PointF[] pts = new PointF[activeMdiChild.DataAsRow.Length];
                for (int i = 0; i < pts.Length; i++)
                {
                    pts[i].X = i;
                    pts[i].Y = (float)activeMdiChild.DataAsRow[i];
                }

                dform = new DekartForm(30, 30, 100, 300);
                ToolStripButton tsb = new ToolStripButton("Рассчет");
                tsb.Click += new EventHandler(dfSFPriodic_dfClosed);
                dform.toolStrip1.Items.Add(tsb);
                dform.AddPolygon(Color.Blue, 2f, DrawModes.DrawPoints, pts);
                dform.MouseClick += new MouseEventHandler(dfSFPeriodic_MouseClick);
                //dform.FormClosed += new FormClosedEventHandler(dfSFPriodic_dfClosed);
                dform.Use_IsVisible = false;
                dform.Show();
                dform.Update2();
            }
        }
예제 #5
0
파일: Form4.cs 프로젝트: a-27m/vssdb
        private void RunWave_Click(object sender, EventArgs e)
        {
            DekartForm dForm = new DekartForm(150, 150, 50, 175);

            dForm.Size = new Size(800, 420);
            dForm.Text = "f(x,t) = |cos(t)|*sin(4x)";

            dForm.Show();

            int tmpID = -1;

            for (t = 0; !dForm.IsDisposed; t += 0.1f)
            {
                if (t > +2 * Math.PI)
                {
                    t -= 2 * (float)Math.PI;
                }

                if (tmpID >= 0)
                {
                    dForm.RemoveGraphic(tmpID);
                }
                tmpID = dForm.AddGraphic(fun, -5, 5,
                                         DrawModes.DrawLines, Color.Red);

                dForm.Update2();                //.DrawAllGraphics();
                Application.DoEvents();
            }
        }
예제 #6
0
        private void FindRoot()
        {
            double          res   = double.NaN;
            List <PointF[]> lines = null;

            #region prepare dform
            if (dForm == null)
            {
                dForm               = new DekartForm(100, 100, 300, 300);
                dForm.Size          = new Size(750, 600);
                dForm.Use_IsVisible = false;
                dForm.toolStripContainer1.ContentPanel.MouseUp +=
                    new MouseEventHandler(dForm_MouseClick);
                dForm.FormClosed += new FormClosedEventHandler(delegate(object s, FormClosedEventArgs eva)
                {
                    ReadPolynom();
                    textBoxFx.Text = poly1.ToString();
                    dForm          = null;
                });
            }
            else
            {
                dForm.RemoveAllGraphics();
            }

            #endregion

            dForm.AddGraphic(f, x1, x2, DrawModes.DrawLines, Color.Green);
            dForm.Show();
            dForm.Update2();

            res      = NewtoneRafson(f, df, p0, eps, out lines, false);
            lastRoot = res;

            #region Print results

            if (lines != null)
            {
                foreach (PointF[] pts in lines)
                {
                    dForm.AddPolygon(Color.Red, DrawModes.DrawLines, pts);
                }
            }

            dForm.Update2();

            if (double.IsNaN(res))
            {
                dForm.Text = "Корни не найдены.";
                return;
            }

            listRoots.Items.Add("x" + (listRoots.Items.Count + 1) + " = "
                                + res.ToString("F16"));
            listY.Items.Add("y" + (listY.Items.Count + 1) + " = "
                            + poly1.Evaluate(res).ToString("F16"));
            #endregion
        }
예제 #7
0
파일: Form01.cs 프로젝트: a-27m/vssdb
        private void task11ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GetDelta();
            DekartForm df = new DekartForm(30, 30, 100, 200);

            df.AddGraphic(new DoubleFunction(f11), -0.7f, 10f, DrawModes.DrawPoints,
                          Color.SpringGreen);
            df.Show2();
        }
예제 #8
0
파일: Form4.cs 프로젝트: a-27m/vssdb
        private void fxItem_Click(object sender, EventArgs e)
        {
            DekartForm dForm = new DekartForm(75, 75, 320, 300);

            dForm.Size = new Size(700, 600);
            dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Green);
            dForm.Use_IsVisible = false;
            dForm.Show();
            dForm.Update2();
        }
예제 #9
0
        void dfSFProgress_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (ActiveMdiChild is FormChild)
                {
                    FormChild activeMdiChild = ActiveMdiChild as FormChild;

                    (sender as Form).Close();

                    double[] data = activeMdiChild.DataAsRow;

                    double sx, sy, sx2, sy2, sxy, n;
                    sx = sy = sx2 = sy2 = sxy = 0;
                    n  = data.Length;

                    for (int i = 0; i < data.Length; i++)
                    {
                        sx  += i;
                        sx2 += i * i;
                        sy  += data[i];
                        sy2 += data[i] * data[i];
                        sxy += i * data[i];
                    }

                    double a, b; // y = ax +b

                    a = (n * sxy - sx * sy) / (n * sx2 - sx * sx);
                    b = (sy * sx2 - sx * sxy) / (n * sx2 - sx * sx);

                    PointF[] pts  = new PointF[data.Length];
                    PointF[] pts0 = new PointF[data.Length];

                    for (int i = 0; i < pts.Length; i++)
                    {
                        // i => x
                        pts[i].X = pts0[i].X = i;

                        // ax*b => y0, data => y
                        pts[i].Y  = (float)data[i];
                        pts0[i].Y = (float)(a * i + b);
                    }

//                    float oneThird = 1f / 3f;

                    DekartForm df = new DekartForm(30, 30, 100, 150);
                    df.AddPolygon(Color.Green, 3f, DrawModes.DrawPoints, pts);
                    df.AddPolygon(Color.Red, 2f, DrawModes.DrawLines, pts0);
                    df.Use_IsVisible = false;
                    df.MouseClick   += new MouseEventHandler(dfSFProgress_MouseClick);
                    df.Show();
                    df.Update2();
                }
            }
        }
예제 #10
0
파일: Form4.cs 프로젝트: a-27m/vssdb
            public static double Muller(DoubleFunction f,
                                        double p1, double p2, double p3, double eps,
                                        ref DekartForm dForm, bool silent)
            {
                double p0;
                int    stepsMaden = 0;

                Parabola parabola = new Parabola(p1, f(p1), p2, f(p2), p3, f(p3));

                dForm.AddGraphic(parabola.Eval,
                                 (float)(double)Min(p1, p2, p3),
                                 (float)(double)Max(p1, p2, p3),
                                 DrawModes.DrawLines, Color.Red);

                do
                {
                    p0 = p1;
                    p1 = p2;
                    p2 = p3;
                    p3 = NextRoot(f, p0, p1, p2);

                    stepsMaden++;

                    parabola = new Parabola(p1, f(p1), p2, f(p2), p3, f(p3));

                    dForm.AddGraphic(parabola.Eval,
                                     (float)(double)Min(p1, p2, p3),
                                     (float)(double)Max(p1, p2, p3),
                                     DrawModes.DrawLines, Color.Red);

                    if (stepsMaden % 100 == 0)
                    {
                        if (silent)
                        {
                            return(double.NaN);
                        }

                        if (MessageBox.Show("Performed " + stepsMaden.ToString()
                                            + " steps, continue?", "Разошлось наверно?",
                                            MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
                                            MessageBoxDefaultButton.Button1) != DialogResult.OK)
                        {
                            return(double.NaN);
                        }
                    }
                }while ((Math.Abs(p3 - p2) >= eps) &&
                        (Math.Abs(f(p3)) > eps));

                return(p3);
            }
예제 #11
0
파일: Form1.cs 프로젝트: a-27m/vssdb
        void solver_DebugMaxMin(FractionPoint max, FractionPoint min, Fraction f_tan)
        {
            if (df == null)
            {
                df      = new DekartForm(100, 100, 100, 100);
                df.Text = "max & min";
            }

            df.Use_IsVisible = false;

            // n
            df.AddPolygon(Color.Black, DrawModes.DrawLines,
                          new PointF(1000, f_tan * 1000),
                          new PointF(-1000, -f_tan * 1000));

            for (float percent = 0; ; percent += .05f)
            {
                int id1 = df.AddPolygon(Color.Black, DrawModes.DrawLines,
                                        new PointF(1000 + max.X * percent, -1 / f_tan * 1000 + max.Y * percent),
                                        new PointF(-1000 + max.X * percent, 1 / f_tan * 1000 + max.Y * percent));
                int id2 = df.AddPolygon(Color.Black, DrawModes.DrawLines,
                                        new PointF(1000 + min.X * percent, -1 / f_tan * 1000 + min.Y * percent),
                                        new PointF(-1000 + min.X * percent, 1 / f_tan * 1000 + min.Y * percent));
                //int id1 = df.AddPolygon(Color.Orange, DrawModes.DrawLines,
                //       new PointF(1000 + max.X * percent, -1 / f_tan * 1000 + max.Y * percent),
                //       new PointF(-1000 + max.X * percent, 1 / f_tan * 1000 + max.Y * percent));
                //int id2 = df.AddPolygon(Color.CornflowerBlue, DrawModes.DrawLines,
                //    new PointF(1000 + min.X * percent, -1 / f_tan * 1000 + min.Y * percent),
                //    new PointF(-1000 + min.X * percent, 1 / f_tan * 1000 + min.Y * percent));
                if (percent >= 0.99f)
                {
                    break;
                }
                df.Update2();
                Application.DoEvents();
                df.RemoveGraphic(id2);
                df.RemoveGraphic(id1);
            }

            //df.AddPolygon(Color.Orange, 3f, DrawModes.DrawPoints, new PointF(max.X, max.Y));
            //df.AddPolygon(Color.CornflowerBlue, 3f, DrawModes.DrawPoints, new PointF(min.X, min.Y));

            df.AddPolygon(Color.Black, 3f, DrawModes.DrawPoints, new PointF(max.X, max.Y));
            df.AddPolygon(Color.Black, 3f, DrawModes.DrawPoints, new PointF(min.X, min.Y));

            df.Show();
            df.Update2();
        }
예제 #12
0
        private void tool_d3f_Click(object sender, EventArgs e)
        {
            try
            {
                a = float.Parse(textBoxA.Text);
                b = float.Parse(textBoxB.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Parsing error, aborted.");
                return;
            }

            if ((!checkBoxReuse.Checked) || (dForm == null))
            {
                dForm      = new DekartForm(75, 75, 25, 150);
                dForm.Size = new Size(400,
                                      Screen.PrimaryScreen.Bounds.Height - 50 /*560*/);
                dForm.Top = 5;
            }
            else
            {
                dForm.RemoveAllGraphics();
            }

            dForm.Text = "'Third derivate' | " +
                         "Green - numeric | " +
                         "Blue - analytic | " +
                         "Red - error o(h^2) | " +
                         "Magenta - error o(h^4)";

            dForm.AddGraphic(d3f_numeric2, a, b, DrawModes.DrawLines,
                             Color.Green);
            dForm.AddGraphic(d3f_numeric4, a, b, DrawModes.DrawLines,
                             Color.Olive);

            dForm.AddGraphic(d3f_analytic, a, b, DrawModes.DrawLines,
                             Color.Blue);

            dForm.AddGraphic(d3f_error2, a, b, DrawModes.DrawLines,
                             Color.Red);
            dForm.AddGraphic(d3f_error4, a, b, DrawModes.DrawLines,
                             Color.Magenta);
            dForm.Show();
        }
예제 #13
0
        void dfSFPeriodic_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (ActiveMdiChild is FormChild)
                {
                    if (clickSentinels == null)
                    {
                        clickSentinels = new List <int>(100);
                    }

                    DekartForm df  = (sender as DekartForm);
                    int        pos = (int)(df.MouseMathLocation.X);

                    if (pos < 0)
                    {
                        return;
                    }
                    if (pos > (ActiveMdiChild as FormChild).DataAsRow.Length - 2)
                    {
                        return;
                    }
                    if (clickSentinels.Contains(pos))
                    {
                        return;
                    }

                    clickSentinels.Add(pos);


                    PointF[] pts = new PointF[2];
                    pts[0].X = pos + 0.5f;
                    pts[1].X = pos + 0.5f;
                    pts[0].Y = 0.5f;
                    pts[1].Y = -0.5f;

                    df.AddPolygon(Color.Red, DrawModes.DrawLines, pts);
                    df.Use_IsVisible = false;
                    df.Update2();
                }
            }
        }
예제 #14
0
파일: Form2.cs 프로젝트: a-27m/vssdb
        private void buttonChe_Click(object sender, EventArgs e)
        {
            try
            {
                a = float.Parse(textBoxA.Text);
                b = float.Parse(textBoxB.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Parsing error, aborted.");
                return;
            }

            n = (int)numericN.Value;
            float h = (b - a) / n;

            givenPoints = new PointF[n + 1];

            // fill table givenPoints with known values
            for (int i = 0; i <= n; i++)
            {
                double ksi = Math.Cos(Math.PI * (2 * i + 1) / (2 * n + 2));
                double xi  = (a + b) / 2.0 - (b - a) / 2.0 * ksi;
                givenPoints[i].X = (float)xi;
                givenPoints[i].Y = (float)f(givenPoints[i].X);
            }

            DekartForm df = new DekartForm(150, 150, 50, 430);

            df.Size = new Size(440, 540);
            df.Text = "n = " + n.ToString() + " | Red - error | " +
                      "Olive - Chebyshev's polynom | Green - f(x)";

            df.AddGraphic(new DoubleFunction(lagrange_err), a, b, DrawModes.DrawLines,
                          Color.Red);
            df.AddGraphic(new DoubleFunction(lagrange), a, b, DrawModes.DrawLines,
                          Color.Olive);
            df.AddGraphic(new DoubleFunction(f), a, b, DrawModes.DrawPoints,
                          Color.Green);
            df.Show();            //.DrawAllGraphics();
        }
예제 #15
0
        private void buttonSysFailProgress_Click(object sender, EventArgs e)
        {
            if (ActiveMdiChild is FormChild)
            {
                FormChild activeMdiChild = ActiveMdiChild as FormChild;

                PointF[] pts = new PointF[activeMdiChild.DataAsRow.Length];
                for (int i = 0; i < pts.Length; i++)
                {
                    pts[i].X = i;
                    pts[i].Y = (float)activeMdiChild.DataAsRow[i];
                }

                DekartForm df = new DekartForm(30, 30, 100, 300);
                df.AddPolygon(Color.Green, 2f, DrawModes.DrawLines, pts);
                df.MouseClick   += new MouseEventHandler(dfSFProgress_MouseClick);
                df.Use_IsVisible = false;
                df.Show();
                df.Update2();
            }
        }
예제 #16
0
        private void tool_df_Click(object sender, EventArgs e)
        {
            try
            {
                a = float.Parse(textBoxA.Text);
                b = float.Parse(textBoxB.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Parsing error, aborted.");
                return;
            }

            if ((!checkBoxReuse.Checked) || (dForm == null))
            {
                dForm      = new DekartForm(150, 150, 50, 200);
                dForm.Size = new Size(730, 560);
            }
            else
            {
                dForm.RemoveAllGraphics();
            }

            dForm.Text = "'First derivate' | " +
                         "Green - numeric | " +
                         "Blue - analytic | " +
                         "Red - error";

            dForm.AddGraphic(df_numeric2, a, b, DrawModes.DrawLines,
                             Color.Green);
            dForm.AddGraphic(df_numeric4, a, b, DrawModes.DrawLines,
                             Color.Olive);
            dForm.AddGraphic(df_analytic, a, b, DrawModes.DrawLines,
                             Color.Blue);
            dForm.AddGraphic(df_error2, a, b, DrawModes.DrawLines,
                             Color.Red);
            dForm.AddGraphic(df_error4, a, b, DrawModes.DrawLines,
                             Color.Magenta);
            dForm.Show();
        }
예제 #17
0
파일: Form2.cs 프로젝트: a-27m/vssdb
        private void buttonNewtone_Click(object sender, EventArgs e)
        {
            try
            {
                a = float.Parse(textBoxA.Text);
                b = float.Parse(textBoxB.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Parsing error, aborted.");
                return;
            }

            n = (int)numericN.Value;
            float h = (b - a) / n;

            givenPoints = new PointF[n + 1];

            // fill table givenPoints with known values
            for (int i = 0; i <= n; i++)
            {
                givenPoints[i].X = a + i * h;
                givenPoints[i].Y = (float)f(givenPoints[i].X);
            }

            DekartForm df = new DekartForm(150, 150, 50, 430);

            df.Size = new Size(440, 540);
            df.Text = "n = " + n.ToString() + " | Red - error | " +
                      "Olive - Newton's interpolation polynom | Green - f(x)";

            df.AddGraphic(new DoubleFunction(newtone_err), a, b, DrawModes.DrawLines,
                          Color.Red);
            df.AddGraphic(new DoubleFunction(newtone), a, b, DrawModes.DrawLines,
                          Color.Olive);
            df.AddGraphic(new DoubleFunction(f), a, b, DrawModes.DrawPoints,
                          Color.Green);
            df.Show();            //.DrawAllGraphics();
        }
예제 #18
0
        private void button1_Click(object sender, EventArgs e)
        {
            DekartForm df = new DekartForm(30, 30, 200, 200);

            List <PointF> pts = new List <PointF>();

            double x1 = -3;
            double x2 = 3;
            double hx = 0.05;

            double y1 = -3;
            double y2 = 3;
            double hy = 0.05;

            for (y = y1; y < y2; y += hy)
            {
                double[] rootX = Iteration(fy0, x1, x2, hx);

                for (int i = 0; i < rootX.Length; i++)
                {
                    pts.Add(new PointF((float)rootX[i], (float)y));
                }
            }

            for (x = x1; x < x2; x += hx)
            {
                double[] rootY = Iteration(fx0, y1, y2, hy);

                for (int i = 0; i < rootY.Length; i++)
                {
                    pts.Add(new PointF((float)x, (float)rootY[i]));
                }
            }


            df.AddPolygon(Color.Gray, DrawModes.DrawPoints, pts.ToArray());
            df.Show();
            df.Update2();
        }
예제 #19
0
파일: Form1.cs 프로젝트: a-27m/vssdb
        void solver_DebugPolygonEvent(FractionPoint[] polygon)
        {
            PointF[] pts = new PointF[polygon.Length];
            for (int i = 0; i < polygon.Length; i++)
            {
                pts[i] = new PointF((float)polygon[i].X.Value, (float)polygon[i].Y.Value);
            }

            if (df == null)
            {
                df             = new DekartForm(75, 75, 250, 200);
                df.Text        = this.Text + " - графическое решение";
                df.FormClosed += new FormClosedEventHandler(delegate(object sender, FormClosedEventArgs e)
                {
                    df = null;
                });
                //df.WindowState = FormWindowState.Maximized;
            }
            //df.RemoveAllGraphics();
            df.AddPolygon(Color.Black, DrawModes.DrawFilledPolygon, pts);
            df.Show();
            df.Update2();
        }
예제 #20
0
파일: Form4.cs 프로젝트: a-27m/vssdb
        private void AutoFindRoots()
        {
            float  x1, x2;
            double eps;

            errorProvider.Clear();

            try
            { eps = float.Parse(textE.Text); }
            catch (FormatException)
            { errorProvider.SetError(textE, "Wrong float number"); return; }
            if (eps < 0)
            {
                errorProvider.SetError(textE, "Has to be > 0"); return;
            }

            try
            { x1 = float.Parse(textX1.Text); }
            catch (FormatException)
            { errorProvider.SetError(textX1, "Wrong float number"); return; }

            try
            { x2 = float.Parse(textX2.Text); }
            catch (FormatException)
            { errorProvider.SetError(textX2, "Wrong float number"); return; }

            float step = (x2 - x1) / 100f;

            DekartForm dForm;

            dForm = new DekartForm(100, 100, 175, 300);
            dForm.Use_IsVisible = false;
            dForm.Size          = new Size(350, 600);
            dForm.CenterView();

            listRoots.Items.Clear();
            listY.Items.Clear();

            roots = new List <double>();

            for (float x = x1; x < x2; x += step)
            {
                double          res   = double.NaN;
                List <PointF[]> lines = null;

                switch (selectedSolMeth)
                {
                    #region Method Still Point
                case SolutionMethod.StillPoint:
                    if (dForm.CountGraphics == 0)
                    {
                        dForm.AddGraphic(g, -5f, 5f,
                                         DrawModes.DrawLines, Color.Green);
                        dForm.AddGraphic(f, -5f, 5f,
                                         DrawModes.DrawLines, Color.Gray);
                        dForm.AddGraphic(bisectress, -5f, 5f,
                                         DrawModes.DrawLines, Color.Blue);
                    }

                    res = FindRoot.StillPointMethod(h, x, eps, out lines, true);
                    break;
                    #endregion

                    #region Method Bisection
                case SolutionMethod.Bisection:
                    if (dForm.CountGraphics == 0)
                    {
                        dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Green);
                    }

                    res = FindRoot.Bisection(h, x, x + step, eps, out lines, true);
                    break;
                    #endregion

                    //#region Method Newtone-Rafson
                    //case SolutionMethod.NewtoneRafson:
                    //    MessageBox.Show("How to evaluate dh/dx?");
                    //    return;
                    //    if ( dForm.CountGraphics == 0 )

                    //        dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Green);

                    //    res = FindRoot.NewtoneRafson(f, df, x, eps, out lines);
                    //    break;

                    //#endregion

                    #region Method Cuttings
                case SolutionMethod.Cuttings:
                    if (dForm.CountGraphics == 0)
                    {
                        dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Green);
                    }
                    res = FindRoot.Cuttings(h, x, x + step, eps, out lines, true);
                    break;
                    #endregion

                    //#region Method Hord
                    //case SolutionMethod.Hord:
                    //    if ( dForm.CountGraphics == 0 )
                    //        dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Green);
                    //    res = FindRoot.Hord(f, d2f, x, x + step, eps, out lines);
                    //    break;
                    //#endregion

                    #region Method Muller
                case SolutionMethod.Muller:
                    if (dForm.CountGraphics == 0)
                    {
                        dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Green);
                    }

                    res   = FindRoot.Muller(h, x - step, x, x + step, eps, ref dForm, true);
                    lines = null;
                    break;

                    #endregion
                default:
                    return;
                }

                if (lines != null)
                {
                    foreach (PointF[] pts in lines)
                    {
                        dForm.AddPolygon(Color.Red, DrawModes.DrawLines, pts);
                    }
                }

                if (double.IsNaN(res))
                {
                    continue;
                }
                if ((res > x2) || (res < x1))
                {
                    continue;
                }

                roots.Add(res);
            }
            roots.Sort();
            foreach (double p in roots)
            {
                listRoots.Items.Add("x" + (listRoots.Items.Count + 1) + " = "
                                    + p.ToString("F16"));
                listY.Items.Add("y" + (listY.Items.Count + 1) + " = "
                                + f(p).ToString("F16"));
            }

            dForm.Show();
            dForm.Update2();
        }
예제 #21
0
파일: Form4.cs 프로젝트: a-27m/vssdb
        private void buttonSolve_Click(object sender, EventArgs e)
        {
            if (checkAutoSearch.Checked)
            {
                AutoFindRoots(); return;
            }

            double p0, p1, p2;
            double eps;

            errorProvider.Clear();

            try
            { eps = float.Parse(textE.Text); }
            catch (FormatException)
            { errorProvider.SetError(textE, "Wrong float number"); return; }
            if (eps < 0)
            {
                errorProvider.SetError(textE, "Has to be > 0");
                return;
            }

            double          res   = double.NaN;
            DekartForm      dForm = null;
            List <PointF[]> lines = null;

            switch (selectedSolMeth)
            {
                #region Method Still Point
            case SolutionMethod.StillPoint:

                try
                { p0 = float.Parse(textP0.Text); }
                catch (FormatException)
                { errorProvider.SetError(textP0, "Wrong float number"); return; }

                dForm      = new DekartForm(100, 100, 320, 300);
                dForm.Size = new Size(700, 500);

                dForm.AddGraphic(g, -5f, 5f, DrawModes.DrawLines, Color.Green);
                dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Gray);
                dForm.AddGraphic(bisectress, -5f, 5f, DrawModes.DrawLines, Color.Blue);

                res = FindRoot.StillPointMethod(f, p0, eps, out lines, false);
                break;
                #endregion

                #region Method Bisection
            case SolutionMethod.Bisection:
                try
                { p0 = float.Parse(textP0.Text); }
                catch (FormatException)
                { errorProvider.SetError(textP0, "Wrong float number"); return; }
                try
                { p1 = float.Parse(textP1.Text); }
                catch (FormatException)
                { errorProvider.SetError(textP1, "Wrong float number"); return; }

                dForm = new DekartForm(100, 100, 175, 300);
                dForm.Use_IsVisible = false;
                dForm.Size          = new Size(350, 600);

                dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Green);

                res = FindRoot.Bisection(f, p0, p1, eps, out lines, false);
                break;

                #endregion

                #region Method Newtone-Rafson
            case SolutionMethod.NewtoneRafson:
                try
                { p0 = float.Parse(textP0.Text); }
                catch (FormatException)
                { errorProvider.SetError(textP0, "Wrong float number"); return; }

                dForm               = new DekartForm(100, 100, 300, 300);
                dForm.Size          = new Size(750, 600);
                dForm.Use_IsVisible = false;

                dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Green);

                res = FindRoot.NewtoneRafson(f, df, p0, eps, out lines, false);
                break;

                #endregion

                #region Method Cuttings
            case SolutionMethod.Cuttings:
                try
                { p0 = float.Parse(textP0.Text); }
                catch (FormatException)
                { errorProvider.SetError(textP0, "Wrong float number"); return; }
                try
                { p1 = float.Parse(textP1.Text); }
                catch (FormatException)
                { errorProvider.SetError(textP1, "Wrong float number"); return; }

                dForm               = new DekartForm(100, 100, 300, 300);
                dForm.Size          = new Size(750, 600);
                dForm.Use_IsVisible = false;

                dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Green);

                res = FindRoot.Cuttings(f, p0, p1, eps, out lines, false);
                break;

                #endregion

                #region Method Hord
            case SolutionMethod.Hord:
                try
                { p0 = float.Parse(textP0.Text); }
                catch (FormatException)
                { errorProvider.SetError(textP0, "Wrong float number"); return; }
                try
                { p1 = float.Parse(textP1.Text); }
                catch (FormatException)
                { errorProvider.SetError(textP1, "Wrong float number"); return; }

                dForm               = new DekartForm(100, 100, 300, 300);
                dForm.Size          = new Size(750, 600);
                dForm.Use_IsVisible = false;

                dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Green);

                res = FindRoot.Hord(f, d2f, p0, p1, eps, out lines, false);

                break;

                #endregion

                #region Method Muller
            case SolutionMethod.Muller:
                try
                { p0 = float.Parse(textP0.Text); }
                catch (FormatException)
                { errorProvider.SetError(textP0, "Wrong float number"); return; }
                try
                { p1 = float.Parse(textP1.Text); }
                catch (FormatException)
                { errorProvider.SetError(textP1, "Wrong float number"); return; }
                try
                { p2 = float.Parse(textP2.Text); }
                catch (FormatException)
                { errorProvider.SetError(textP2, "Wrong float number"); return; }

                dForm               = new DekartForm(100, 100, 300, 300);
                dForm.Size          = new Size(750, 600);
                dForm.Use_IsVisible = false;

                dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Green);

                res = FindRoot.Muller(f, p0, p1, p2, eps, ref dForm, false);

                lines = null;
                break;
                #endregion

            default:
                return;
            }

            #region Print results

            if (lines != null)
            {
                foreach (PointF[] pts in lines)
                {
                    dForm.AddPolygon(Color.Red, DrawModes.DrawLines, pts);
                }
            }
            dForm.Show();
            dForm.Update2();

            listRoots.Items.Clear();
            listY.Items.Clear();

            if (double.IsNaN(res))
            {
                MessageBox.Show("Корни не найдены.");
                return;
            }

            listRoots.Items.Add("x" + (listRoots.Items.Count + 1) + " = "
                                + res.ToString("F16"));
            listY.Items.Add("y" + (listY.Items.Count + 1) + " = "
                            + f(res).ToString("F16"));
            #endregion
        }
예제 #22
0
        void dfSFPriodic_dfClosed(object sender, EventArgs e)
        {
            float oneThird = 1f / 3f;

            if (ActiveMdiChild is FormChild)
            {
                FormChild activeMdiChild = ActiveMdiChild as FormChild;

                double[] data = activeMdiChild.DataAsRow;

                DekartForm df = dform;

                PointF[] pts;

                if (!clickSentinels.Contains(data.Length - 1))
                {
                    clickSentinels.Add(data.Length - 1);
                }
                double[] m = new double[clickSentinels.Count];
                clickSentinels.Sort();

                if (grIds == null)
                {
                    grIds = new List <int>(100);
                }
                else
                {
                    try
                    {
                        for (int i = 0; i < grIds.Count; i++)
                        {
                            df.RemoveGraphic(grIds[i]);

                            for (int l = 0; l < grIds.Count; l++)
                            {
                                if (grIds[l] > grIds[i])
                                {
                                    grIds[l]--;
                                }
                            }
                        }
                    }
                    catch (ArgumentOutOfRangeException) { }

                    grIds.Clear();
                }

                int first = 0;
                for (int i = 0; i < clickSentinels.Count; i++)
                {
                    pts = new PointF[2];
                    for (int k = first; k <= clickSentinels[i]; k++)
                    {
                        m[i] += data[k];
                    }
                    m[i] /= clickSentinels[i] - first + 1;

                    pts[0].X = first - oneThird;
                    pts[1].X = clickSentinels[i] + oneThird;
                    pts[0].Y = pts[1].Y = (float)m[i];

                    grIds.Add(df.AddPolygon(Color.Red, 2f, DrawModes.DrawLines, pts));

                    first = clickSentinels[i] + 1;
                }

                //pts = new PointF[data.Length];
                //for (int i = 0; i < data.Length; i++)
                //{
                //    pts[i].X = i;
                //    pts[i].Y = (float)data[i];
                //}
                //df.AddPolygon(Color.Green, 3f, DrawModes.DrawPoints, pts);

                df.Use_IsVisible = false;
                df.Show();
                df.Update2();
            }
        }
예제 #23
0
파일: Form4.cs 프로젝트: a-27m/vssdb
        private void RollStar_Click(object sender, EventArgs e)
        {
            DekartForm dForm = new DekartForm(150, 150, 180, 175);

            dForm.Use_IsVisible = false;
            dForm.Size          = new Size(400, 425);
            dForm.Text          = "f(x) = 5sin(x^3)-x";
            dForm.Show();

            int    k      = 7;
            int    tmpID  = -1;
            int    grnVal = 150;
            int    grnDx  = 1;
            Random rnd    = new Random((int)(DateTime.Now.Ticks));

            for (float phi = -0.01f; !dForm.IsDisposed;
                 //phi += phi/5 )  //for !crazy!
                 phi += -0.008f)                 //normal
            {
                grnVal += ((grnVal < 100) || (grnVal > 200))
                                        ? grnDx *= -1 : grnDx;

                if (phi < -2 * Math.PI)
                {
                    phi += 2 * (float)Math.PI;
                }

                int      l   = 0;
                PointF[] pts = new PointF[k * k];
                float    r   = 0.5f * (float)Math.Abs(Math.Cos(3 * phi)) + 0.5f;
                //Math.Abs(Math.Cos(t) + 0.5);
                for (int i = 0; i < k; i++)
                {
                    PointF pti = new PointF(
                        r * (float)Math.Cos(2 * i * Math.PI / k + phi),
                        r * (float)Math.Sin(2 * i * Math.PI / k + phi));
                    for (int j = 0; j < i; j++)
                    {
                        if ((j == i - 1) ||
                            (j == 0 && i == k - 1))
                        {
                            continue;
                        }
                        pts[l++] = pti;
                        pts[l++] = new PointF(
                            r * (float)Math.Cos(2 * j * Math.PI / k + phi),
                            r * (float)Math.Sin(2 * j * Math.PI / k + phi)
                            );
                    }
                }

                Array.Resize <PointF>(ref pts, l);

                Color cl = Color.FromArgb(100, grnVal, 100);

                if (tmpID >= 0)
                {
                    dForm.RemoveGraphic(tmpID);
                }

                tmpID = dForm.AddPolygon(cl, 2f, DrawModes.DrawLines, pts);
                dForm.Update2();
                //.DrawAllGraphics();
                Application.DoEvents();
            }
        }
예제 #24
0
파일: Form1.cs 프로젝트: a-27m/vssdb
 public Form1()
 {
     InitializeComponent();
     df = new DekartForm(100, 100, 300, 150);
     df.CoodrinateSystemDrawn += new PaintEventHandler(df_CoodrinateSystemDrawn);
 }
예제 #25
0
        private void buttonSolve_Click(object sender, EventArgs e)
        {
            double x0, y0;
            double eps;
            bool   speedUp;

            #region get parameters from form
            errorProvider.Clear();

            try { eps = float.Parse(textE.Text); }
            catch (FormatException) {
                errorProvider.SetError(textE, "Wrong float number");
                return;
            }
            if (eps < 0)
            {
                errorProvider.SetError(textE, "Has to be > 0");
                return;
            }

            speedUp = checkSpeedUp.Checked;
            #endregion

            double[]        res   = new double[] { double.NaN, double.NaN };
            DekartForm      dForm = null;
            List <PointF[]> lines = null;

            switch (selectedSolMeth)
            {
                #region Method Simple Iteration

            case SolutionMethod.StillPoint:

                try { x0 = float.Parse(textX0.Text); }
                catch (FormatException) { errorProvider.SetError(textX0, "Wrong float number"); return; }

                try { y0 = float.Parse(textY0.Text); }
                catch (FormatException) { errorProvider.SetError(textY0, "Wrong float number"); return; }

                dForm               = new DekartForm(200, 200, 200, 300);
                dForm.Size          = new Size(750, 600);
                dForm.Use_IsVisible = false;

                dForm.AddGraphic(f1x, f1yS, -5f, 5f, DrawModes.DrawLines, Color.Green);
                dForm.AddGraphic(f2xS, f2y, -5f, 5f, DrawModes.DrawLines, Color.Blue);
                res = FindSysRoot.StillPointMethod(
                    new double[] { x0, y0 },
                    new DoubleFunction[] { g1S, g2S },
                    eps, out lines, speedUp, false);
                break;
                #endregion

                #region Method Newtone

            case SolutionMethod.Newtone:

                try { x0 = float.Parse(textX0.Text); }
                catch (FormatException) { errorProvider.SetError(textX0, "Wrong float number"); return; }

                try { y0 = float.Parse(textY0.Text); }
                catch (FormatException) { errorProvider.SetError(textY0, "Wrong float number"); return; }

                dForm               = new DekartForm(100, 100, 300, 300);
                dForm.Size          = new Size(750, 600);
                dForm.Use_IsVisible = false;

                dForm.AddGraphic(f1x, f1y, -5f, 5f, DrawModes.DrawLines, Color.Green);
                dForm.AddGraphic(f2x, f2y, -5f, 5f, DrawModes.DrawLines, Color.Blue);

                DoubleMultiDimFunction[,] J = new DoubleMultiDimFunction[2, 2];
                J[0, 0] = df1x;
                J[0, 1] = df1y;
                J[1, 0] = df2x;
                J[1, 1] = df2y;

                DoubleMultiDimFunction[] F = new DoubleMultiDimFunction[2];
                F[0] = f1;
                F[1] = f2;

                res = FindSysRoot.Newtone(F, J,
                                          new double[] { x0, y0 }, eps, out lines, false);
                break;

                #endregion

            default:
                return;
            }

            #region Print results

            if (lines != null)
            {
                foreach (PointF[] pts in lines)
                {
                    dForm.AddPolygon(Color.Red, DrawModes.DrawLines, pts);
                }
            }
            dForm.Show();
            dForm.Update2();

            listRoots.Items.Clear();
            listY.Items.Clear();

            if (double.IsNaN(res[0]) || double.IsNaN(res[1]))
            {
                MessageBox.Show("Корни не найдены.");
                return;
            }

            listRoots.Items.Add("x" + (listRoots.Items.Count + 1) + " = "
                                + res[0].ToString("F16"));
            listY.Items.Add("y" + (listY.Items.Count + 1) + " = "
                            + res[1].ToString("F16"));
            #endregion
        }
예제 #26
0
파일: Form1.cs 프로젝트: a-27m/vssdb
        private void buttonDraw_Click(object sender, EventArgs e)
        {
            errorProvider1.Clear();
            bool ok = true;

            try
            {
                x1 = float.Parse(textBox1.Text);
            }
            catch (FormatException)
            {
                errorProvider1.SetError(textBox1, "Неверный формат вещественного числа");
                ok = false;
            }

            try
            {
                x2 = float.Parse(textBox2.Text);
            }
            catch (FormatException)
            {
                errorProvider1.SetError(textBox2, "Неверный формат вещественного числа");
                ok = false;
            }

            if (!ok)
            {
                return;
            }

            if (x1 > x2)
            {
                float t = x1;
                x1 = x2;
                x2 = t;

                textBox1.Text = x1.ToString();
                textBox2.Text = x2.ToString();
            }

            listBox1.Items.Add(string.Format("Интервал: [{0}; {1}]", x1, x2));

            DekartForm df = new DekartForm(50, 50, 30, 150);

            df.Text = "y ≈ sin(x)";
            df.AddGraphic(new DoubleFunction(delegate(double x)
            {
                double a, sum = x;
                uint n        = 2;
                a             = x;
                do
                {
                    a   *= -x * x / n / (n + 1);
                    sum += a;
                    n   += 2;
                }while (Math.Abs(a) >= eps);

                listBox1.Items.Add("x = " + x.ToString("f3") + ", n = " + n.ToString());
                return(sum);
            }), x1, x2, DrawModes.DrawPoints, Color.Green);

            df.Show();
            df.Update2();
        }
예제 #27
0
파일: Form1.cs 프로젝트: a-27m/vssdb
        private void FindRoot()
        {
            Complex res = Complex.NaN;

            #region prepare dform
            if (dForm == null)
            {
                dForm               = new DekartForm(100, 100, 300, 300);
                dForm.ClientSize    = new Size(600, 600);
                dForm.Use_IsVisible = false;
                dForm.FormClosed   += new FormClosedEventHandler(delegate(object s, FormClosedEventArgs eva)
                {
                    dForm = null;
                });
            }
            else
            {
                dForm.RemoveAllGraphics();
            }

            #endregion

            List <Root>   roots  = new List <Root>();
            List <PointF> pts    = new List <PointF>();
            List <Color>  colors = new List <Color>();

            Color[] baseColors = new Color[] {
                Color.Red,
                Color.Orange,
                Color.Yellow,
                Color.Green,
                Color.LightBlue,
                Color.Blue,
                Color.Violet
            };

            double y1 = x1, y2 = x2;

            DoubleOfVectorFunction[] dovf = new DoubleOfVectorFunction[] { f1, f2 };
            Complex c = new Complex(0);

            for (double y = y1; y < y2; y += hy)
            {
                for (double x = x1; x < x2; x += hx)
                {
                    int   iterations;
                    float percent;
                    c.re = x;
                    c.im = y;
                    res  = Newtone(dovf, c, eps, out iterations);

                    bool inRange = true;
                    inRange &= res.re > x1;
                    inRange &= res.re < x2;
                    inRange &= res.im > y1;
                    inRange &= res.im < y2;


                    if (Complex.IsNaN(res) || !inRange)
                    {
                        colors.Add(Color.Black);
                        pts.Add(new PointF((float)x, (float)y));
                    }
                    else
                    {
                        if (roots.Count == 0)
                        {
                            Root newRoot;
                            newRoot.color = baseColors[roots.Count % baseColors.Length];
                            newRoot.value = res;
                            roots.Add(newRoot);
                        }

                        percent = iterations / 15f;
                        if (percent > 1f)
                        {
                            percent = 1f;
                        }

                        bool needAdd = true;
                        foreach (Root r in roots)
                        {
                            if (Near(r.value, res))
                            {
                                colors.Add(ColorModifer.Brightness(r.color, percent));
                                pts.Add(new PointF((float)x, (float)y));

                                needAdd = false;
                                break;
                            }
                        }

                        if (needAdd)
                        {
                            Root newRoot;
                            newRoot.color = baseColors[roots.Count % baseColors.Length];
                            newRoot.value = res;
                            roots.Add(newRoot);

                            colors.Add(ColorModifer.Brightness(newRoot.color, percent));
                            pts.Add(new PointF((float)x, (float)y));
                        }
                    }
                }
            }

            DotGraphic dotGraphic = new DotGraphic(pts.ToArray(), colors.ToArray());
            dotGraphic.CurrentColorSchema = new MathGraphic.ColorSchema(
                Color.Black, Color.DimGray, Color.DimGray, Color.Gray);
            dForm.AddGraphic(dotGraphic);

            MathGraphic mg;
            mg = new MathGraphic(Color.White, DrawModes.DrawLines, f1x, f1y,
                                 -5f, 5f, 0.01f);
            dForm.AddGraphic(mg);

            mg = new MathGraphic(Color.White, DrawModes.DrawLines, f2x, f2y,
                                 -5f, 5f, 0.01f);
            dForm.AddGraphic(mg);

            dForm.Show();
            dForm.Update2();

            foreach (Root z in roots)
            {
                listRoots.Items.Add("z" + (listRoots.Items.Count + 1) + " = "
                                    + z.value.ToString("F6"));
                listY.Items.Add("f,g" + (listY.Items.Count + 1) + " = "
                                + f1(z.value.re, z.value.im).ToString("F6") + ", "
                                + f2(z.value.re, z.value.im).ToString("F6"));
            }
        }
예제 #28
0
        void dfSFConst_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (ActiveMdiChild is FormChild)
                {
                    FormChild activeMdiChild = ActiveMdiChild as FormChild;

                    (sender as Form).Close();

                    int last_i1;
                    last_i1 = (int)(sender as DekartForm).MouseMathLocation.X;
                    //MessageBox.Show(last_i1.ToString());

                    double[] data  = activeMdiChild.DataAsRow;
                    double[] data1 = new double[last_i1 + 1];
                    double[] data2 = new double[data.Length - data1.Length];

                    for (int i = 0; i <= last_i1; i++)
                    {
                        data1[i] = data[i];
                    }
                    for (int i = last_i1 + 1; i < data.Length; i++)
                    {
                        data2[i - (last_i1 + 1)] = data[i];
                    }

                    PointF[] pts  = new PointF[data.Length];
                    PointF[] pts0 = new PointF[2];
                    PointF[] pts1 = new PointF[2];
                    PointF[] pts2 = new PointF[2];

                    for (int i = 0; i < pts.Length; i++)
                    {
                        pts[i].X = i;
                        pts[i].Y = (float)data[i];
                    }

                    float m0 = (float)StatisticsProcessor.Srednee(data);
                    float m1 = (float)StatisticsProcessor.Srednee(data1);
                    float m2 = (float)StatisticsProcessor.Srednee(data2);

                    float oneThird = 1f / 3f;
                    pts0[0].X = 0 - oneThird; pts0[0].Y = m0;
                    pts0[1].X = pts.Length - 1 + oneThird; pts0[1].Y = m0;

                    pts1[0].X = 0 - oneThird; pts1[0].Y = m1;
                    pts1[1].X = last_i1 + oneThird; pts1[1].Y = m1;

                    pts2[0].X = last_i1 + 1 - oneThird; pts2[0].Y = m2;
                    pts2[1].X = data.Length - 1 + oneThird; pts2[1].Y = m2;

                    DekartForm df = new DekartForm(30, 30, 100, 150);
                    df.AddPolygon(Color.Green, 3f, DrawModes.DrawPoints, pts);
                    df.AddPolygon(Color.Pink, 2f, DrawModes.DrawLines, pts0);
                    df.AddPolygon(Color.Red, 2f, DrawModes.DrawLines, pts1);
                    df.AddPolygon(Color.Red, 2f, DrawModes.DrawLines, pts2);
                    df.Use_IsVisible = false;
                    df.MouseClick   += new MouseEventHandler(dfSFConst_MouseClick);
                    df.Show();
                    df.Update2();
                }
            }
        }
예제 #29
0
파일: Form2.cs 프로젝트: a-27m/vssdb
        private void buttonSplines_Click(object sender, EventArgs e)
        {
            try
            {
                a = float.Parse(textBoxA.Text);
                b = float.Parse(textBoxB.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Parsing error, aborted.");
                return;
            }

            n = (int)numericN.Value;
            float h = (b - a) / n;

            givenPoints = new PointF[n + 1];

            // fill table givenPoints with known values
            for (int i = 0; i <= n; i++)
            {
                givenPoints[i].X = a + i * h;
                givenPoints[i].Y = (float)f(givenPoints[i].X);
            }

            double[] P = new double[n + 1];
            double[] q = new double[n + 1];
            m = new double[n + 1];

            double[] _a = new double[n];
            double[] _b = new double[n];
            double[] _c = new double[n];
            double[] _v = new double[n];

            m[0]  = m[n] = 0;
            _b[0] = 2 * (H(0) + H(1));

            for (int k = 0; k < n; k++)
            {
                _a[k] = H(k);
                if (k > 0)
                {
                    _b[k] = 2 * (H(k - 1) + H(k));
                }
                if (k < n - 1)
                {
                    _c[k] = H(k + 1);
                }
                if (k > 0)
                {
                    _v[k] = 6 * (D(k) - D(k - 1));
                }
            }

            P[n - 1] = givenPoints[n - 1].Y / H(n - 1);
            q[n - 1] = givenPoints[n].Y / H(n - 1);

            for (int k = n - 1; k > 0; k--)
            {
                P[k - 1] = -_a[k] / (_b[k] + _c[k] * P[k]);
                q[k - 1] = (_v[k] - _c[k] * q[k]) / (_b[k] + _c[k] * P[k]);
            }

            m[1] = (_v[1] - _c[1] * q[1]) / (_b[1] + _c[1] * P[1]);

            for (int k = 1; k < n - 1; k++)
            {
                m[k + 1] = P[k] * m[k] + q[k];
            }

            DekartForm df = new DekartForm(150, 150, 50, 430);

            df.Size = new Size(440, 540);
            df.Text = "n = " + n.ToString() + " | Red - error | " +
                      "Olive - Splines (natural), Green - f(x)";

            df.AddGraphic(new DoubleFunction(splines_err), a, b, DrawModes.DrawLines,
                          Color.Red);
            df.AddGraphic(new DoubleFunction(splines), a, b, DrawModes.DrawLines,
                          Color.Olive);
            df.AddGraphic(new DoubleFunction(f), a, b, DrawModes.DrawPoints,
                          Color.Green);
            df.Show();            //.DrawAllGraphics();
        }