Ejemplo n.º 1
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();
                }
            }
        }
Ejemplo n.º 2
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();
            }
        }
Ejemplo n.º 3
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
        }
Ejemplo n.º 4
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();
                }
            }
        }
Ejemplo n.º 5
0
Archivo: Form1.cs Proyecto: 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();
        }
Ejemplo n.º 6
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();
            }
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
0
Archivo: Form4.cs Proyecto: 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();
        }
Ejemplo n.º 9
0
Archivo: Form4.cs Proyecto: 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
        }
Ejemplo n.º 10
0
Archivo: Form4.cs Proyecto: 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();
            }
        }
Ejemplo n.º 11
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
        }
Ejemplo n.º 12
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();
            }
        }
Ejemplo n.º 13
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();
                }
            }
        }