Пример #1
0
        public void DrawIntegr(ref Grid gr, Fraction a, Fraction b, int res = 100)
        {
            int      por    = this.NCol - 2;
            int      row    = 1;
            Fraction xfrMin = new Fraction();
            Fraction yfrMin = new Fraction();
            Fraction xfrMax = new Fraction();
            Fraction yfrMax = new Fraction();

            //Fraction xfr0 = new Fraction((int)((gr.Width - 20) / 2), 1);
            //Fraction yfr0 = new Fraction((int)((gr.Height - 20) / 2), 1);
            xfrMin = this.matr.A[1, 0].CopyFr;
            //yfrMin.FractTxt = this.txtBxs[1, 1].Text;
            //double yMin = yfrMin.ToDouble();
            Fraction h = new Fraction();

            xfrMax = this.matr.A[this.NRow - 1, 0].CopyFr;
            //double xMax = xfrMax.ToDouble();
            yfrMax = this.matr.A[this.NRow - 1, 1].CopyFr;
            yfrMin = this.matr.A[1, 1].CopyFr;
            for (Fraction i = xfrMin; i <= xfrMax; i += (xfrMax - xfrMin) / 50)
            {
                if (GetPolyNewtonVal(i, por, row) >= yfrMax)
                {
                    yfrMax = GetPolyNewtonVal(i, por, row);
                }
            }
            for (Fraction i = xfrMin; i <= xfrMax; i += (xfrMax - xfrMin) / 50)
            {
                if (GetPolyNewtonVal(i, por, row) < yfrMin)
                {
                    yfrMin = GetPolyNewtonVal(i, por, row);
                }
            }
            CoordAxis axis = new CoordAxis(ref gr, xfrMin.ToDouble(), xfrMax.ToDouble(), yfrMin.ToDouble(), yfrMax.ToDouble(), 10);

            //Fraction yMult = new Fraction((int)((gr.Height - 20) * 1000), 1000);
            h = (b - a) / res;
            PointCollection pc = new PointCollection();

            for (Fraction i = a; i <= b; i += h)
            {
                //pc.Add(new System.Windows.Point((xfr0 + i*xMult).ToDouble(), (yfr0 - GetPolyNewtonVal(i, por, row)*yMult).ToDouble()));
                pc.Add(axis.ConvertCoord(i.ToDouble(), GetPolyNewtonVal(i, por, row).ToDouble()));
            }

            //double wdt = gr.Width - 20;
            //double hgt = gr.Height - 20;

            PointCollection pgPt = new PointCollection();

            pgPt.Add(axis.ConvertCoord(a.ToDouble(), 0));
            foreach (Point pt in pc)
            {
                pgPt.Add(pt);
            }
            pgPt.Add(axis.ConvertCoord(b.ToDouble(), 0));
            Polygon pg = new Polygon();

            pg.Points = pgPt;
            pg.Fill   = Brushes.Pink;
            gr.Children.Add(pg);
        }
Пример #2
0
        public void DrawCircles(Matr m)
        {
            double   mult = 1;
            Fraction r    = new Fraction();
            Fraction a    = new Fraction();

            for (int i = 0; i < m.NCol; i++)
            {
                for (int j = 0; j < m.NCol; j++)
                {
                    if (i != j)
                    {
                        a = m.A[i, j].CopyFr;
                        if (a < 0)
                        {
                            a = -1 * a;
                        }
                        r += a;
                    }
                }
                a = m.A[i, i].CopyFr;
                if (Math.Min((grdGraf.Width - 40) / (2 * (r + (a < 0 ? -1 * a : a))).ToDouble(), (grdGraf.Height - 40) / (2 * r).ToDouble()) <= mult || mult == 1)
                {
                    mult = Math.Min((grdGraf.Width - 40) / (2 * (r + (a < 0 ? -1 * a : a))).ToDouble(), (grdGraf.Height - 40) / (2 * r).ToDouble());
                }
                r.FractTxt = "0";
                a.FractTxt = "0";
            }

            for (int i = 0; i < m.NCol; i++)
            {
                for (int j = 0; j < m.NCol; j++)
                {
                    if (i != j)
                    {
                        a = m.A[i, j].CopyFr;
                        if (a < 0)
                        {
                            a = -1 * a;
                        }
                        r += a;
                    }
                }
                a = m.A[i, i].CopyFr;
                Ellipse   el   = new Ellipse();
                TextBlock xVal = new TextBlock();
                TextBlock rT   = new TextBlock();
                Line      rad  = new Line();
                el.Stroke                = Brushes.Black;
                rad.Stroke               = Brushes.Red;
                rad.StrokeThickness      = 3;
                xVal.Width               = 60;
                el.HorizontalAlignment   = HorizontalAlignment.Left;
                xVal.HorizontalAlignment = HorizontalAlignment.Left;
                rT.HorizontalAlignment   = HorizontalAlignment.Left;
                el.VerticalAlignment     = VerticalAlignment.Top;
                xVal.VerticalAlignment   = VerticalAlignment.Top;
                rT.VerticalAlignment     = VerticalAlignment.Top;
                el.Margin                = new Thickness(grdGraf.Width / 2 - mult * r.ToDouble() + mult * a.ToDouble(), grdGraf.Height / 2 - mult * r.ToDouble(), 0, 0);
                xVal.Margin              = new Thickness(grdGraf.Width / 2 + mult * a.ToDouble() - xVal.Width / 2, grdGraf.Height / 2 + 10, 0, 0);
                rT.Margin                = new Thickness(grdGraf.Width / 2 + mult * a.ToDouble(), grdGraf.Height / 2 - mult * r.ToDouble() - 20, 0, 0);
                rad.X1 = rad.X2 = grdGraf.Width / 2 + mult * a.ToDouble();
                rad.Y1 = grdGraf.Height / 2;
                rad.Y2 = grdGraf.Height / 2 - mult * r.ToDouble();

                xVal.Text          = "" + a.ToDouble();
                rT.Text            = "r" + (i + 1) + " = " + r.ToDouble();
                xVal.TextAlignment = TextAlignment.Center;
                el.Width           = mult * r.ToDouble() * 2;
                el.Height          = mult * r.ToDouble() * 2;
                grdGraf.Children.Add(el);
                grdGraf.Children.Add(xVal);
                grdGraf.Children.Add(rad);
                grdGraf.Children.Add(rT);
                r.FractTxt = "0";
            }
        }
Пример #3
0
        public void DrawPolynom(ref Grid gr, int por, Fraction x, int row = 1, int res = 100)
        {
            Fraction xfrMin = new Fraction();
            Fraction yfrMin = new Fraction();
            Fraction xfrMax = new Fraction();
            Fraction yfrMax = new Fraction();

            xfrMin = this.matr.A[1, 0].CopyFr;
            yfrMin = this.matr.A[1, 1].CopyFr;
            //double yMin = yfrMin.ToDouble();
            Fraction h = new Fraction();

            xfrMax = this.matr.A[this.NRow - 1, 0].CopyFr;
            //double xMax = xfrMax.ToDouble();
            yfrMax = this.matr.A[this.NRow - 1, 1].CopyFr;
            for (Fraction i = xfrMin; i <= xfrMax; i += (xfrMax - xfrMin) / res)
            {
                if (GetPolyNewtonVal(i, por, row) >= yfrMax)
                {
                    yfrMax = GetPolyNewtonVal(i, por, row);
                }
            }
            for (Fraction i = xfrMin; i <= xfrMax; i += (xfrMax - xfrMin) / res)
            {
                if (GetPolyNewtonVal(i, por, row) < yfrMin)
                {
                    yfrMin = GetPolyNewtonVal(i, por, row);
                }
            }
            CoordAxis axis = new CoordAxis(ref gr, xfrMin.ToDouble(), xfrMax.ToDouble(), yfrMin.ToDouble(), yfrMax.ToDouble(), 10);

            axis.DrawAxis();
            //Fraction xMult = new Fraction((int)((gr.Width - 20)*1000), 1000);
            //xMult /= xfrMax*2;
            //Fraction yMult = new Fraction((int)((gr.Height - 20)*1000), 1000);
            //yMult /= yfrMax*2;
            h = (xfrMax - xfrMin) / res;

            Polyline pl = new Polyline();

            Ellipse el = new Ellipse();

            el.HorizontalAlignment = HorizontalAlignment.Left;
            el.VerticalAlignment   = VerticalAlignment.Top;
            el.Width  = 8;
            el.Height = 8;
            Point valXY = axis.ConvertCoord(x.ToDouble(), (GetPolyNewtonVal(x, por, row).ToDouble()));

            System.Windows.Thickness th = new System.Windows.Thickness(valXY.X - el.Width / 2, valXY.Y - el.Height / 2, 0, 0);
            el.Margin = th;

            el.Stroke = Brushes.Red;
            el.Fill   = Brushes.Red;

            PointCollection pc = new PointCollection();

            for (Fraction i = xfrMin; i <= xfrMax; i += h)
            {
                //pc.Add(new System.Windows.Point((xfr0 + i*xMult).ToDouble(), (yfr0 - GetPolyNewtonVal(i, por, row)*yMult).ToDouble()));
                pc.Add(axis.ConvertCoord(i.ToDouble(), GetPolyNewtonVal(i, por, row).ToDouble()));
            }
            pl.Points          = pc;
            pl.Stroke          = Brushes.Blue;
            pl.StrokeThickness = 4;
            double wdt  = gr.Width - 20;
            double hgt  = gr.Height - 20;
            Line   xVal = new Line();

            //xVal.X1 = (xfr0 + x * xMult).ToDouble();
            xVal.X1              = axis.ConvertCoord(x.ToDouble(), GetPolyNewtonVal(x, por, row).ToDouble()).X;
            xVal.Y1              = axis.ConvertCoord(x.ToDouble(), GetPolyNewtonVal(x, por, row).ToDouble()).Y;
            xVal.X2              = xVal.X1;
            xVal.Y2              = axis.crossAxis.Y;
            xVal.Stroke          = Brushes.Red;
            xVal.StrokeDashArray = new DoubleCollection()
            {
                8, 4
            };
            Line yVal = new Line();

            yVal.X1              = axis.ConvertCoord(x.ToDouble(), GetPolyNewtonVal(x, por, row).ToDouble()).X;
            yVal.Y1              = axis.ConvertCoord(x.ToDouble(), GetPolyNewtonVal(x, por, row).ToDouble()).Y;
            yVal.X2              = axis.crossAxis.X;
            yVal.Y2              = yVal.Y1;
            yVal.Stroke          = Brushes.Red;
            yVal.StrokeDashArray = new DoubleCollection()
            {
                8, 4
            };
            gr.Children.Add(pl);
            gr.Children.Add(xVal);
            gr.Children.Add(yVal);


            TextBox valX = new TextBox();

            valX.Text   = "" + x.ToDouble();
            valX.Width  = 100;
            valX.Height = 25;
            valX.HorizontalAlignment = HorizontalAlignment.Left;
            valX.VerticalAlignment   = VerticalAlignment.Top;
            TextBox valY = new TextBox();

            valY.Text   = "" + GetPolyNewtonVal(x, por, row).ToDouble();
            valY.Width  = 200;
            valY.Height = 25;
            valY.HorizontalAlignment = HorizontalAlignment.Left;
            valY.VerticalAlignment   = VerticalAlignment.Top;
            TextBox polyErr  = new TextBox();
            TextBox diff1    = new TextBox();
            TextBox diff2    = new TextBox();
            TextBox diff1Err = new TextBox();
            TextBox diff2Err = new TextBox();

            polyErr.Text    = "погр. интерполирования равна " + GetPolyNewtonErr(x, por, row).ToDouble();
            diff1.Text      = "первая производная равна " + GetPolyNewtonDiff1Val(x, por, row).ToDouble();
            diff1Err.Text   = "ошибка первой производной " + GetPolyNewtonDiff1Err(x, por, row).ToDouble();
            diff2.Text      = "вторая производная равна " + GetPolyNewtonDiff2Val(x, por, row).ToDouble();
            diff2Err.Text   = "ошибка второй производной " + GetPolyNewtonDiff2Err(x, por, row).ToDouble();
            polyErr.Width   = 300;
            polyErr.Height  = 25;
            diff1.Width     = 300;
            diff1.Height    = 25;
            diff2.Width     = 300;
            diff2.Height    = 25;
            diff1Err.Width  = 300;
            diff1Err.Height = 25;
            diff2Err.Width  = 300;
            diff2Err.Height = 25;
            SolidColorBrush br = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));

            valY.BorderBrush                 = br;
            valX.BorderBrush                 = br;
            polyErr.BorderBrush              = br;
            diff1.BorderBrush                = br;
            diff2.BorderBrush                = br;
            diff1Err.BorderBrush             = br;
            diff2Err.BorderBrush             = br;
            valX.Background                  = br;
            valY.Background                  = br;
            polyErr.Background               = br;
            diff1.Background                 = br;
            diff2.Background                 = br;
            diff1Err.Background              = br;
            diff2Err.Background              = br;
            valX.HorizontalContentAlignment  = System.Windows.HorizontalAlignment.Center;
            diff1.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
            diff2.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
            polyErr.Margin  = new System.Windows.Thickness(0, 0, wdt - diff1.Width, hgt - diff1.Height);
            diff1.Margin    = new System.Windows.Thickness(0, 0, wdt - diff1.Width, hgt - 3 * diff1.Height);
            diff1Err.Margin = new System.Windows.Thickness(0, 0, wdt - diff1.Width, hgt - 5 * diff1.Height);
            diff2.Margin    = new System.Windows.Thickness(0, 0, wdt - diff2.Width, hgt - 7 * diff2.Height);
            diff2Err.Margin = new System.Windows.Thickness(0, 0, wdt - diff2.Width, hgt - 9 * diff2.Height);
            if (valXY.Y <= axis.crossAxis.Y)
            {
                valX.Margin = new System.Windows.Thickness(valXY.X - valX.Width / 2, axis.crossAxis.Y - valY.Height, 0, 0);
            }
            else
            {
                valX.Margin = new System.Windows.Thickness(valXY.X - valX.Width / 2, axis.crossAxis.Y + valY.Height, 0, 0);
            }
            if (valXY.X <= axis.crossAxis.X)
            {
                valY.Margin        = new System.Windows.Thickness(axis.crossAxis.X - axis.bord - valY.Width, valXY.Y - valY.Height, 0, 0);
                valY.TextAlignment = axis.taY;
            }
            else
            {
                valY.Margin = new System.Windows.Thickness(axis.crossAxis.X + axis.bord, valXY.Y - valY.Height, 0, 0);
                //valY.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
                valY.TextAlignment = axis.taY;
            }

            gr.Children.Add(el);
            gr.Children.Add(valX);
            gr.Children.Add(valY);
            gr.Children.Add(polyErr);
            gr.Children.Add(diff1);
            gr.Children.Add(diff2);
            gr.Children.Add(diff1Err);
            gr.Children.Add(diff2Err);
        }