示例#1
0
        // linearni regrese
        // y=ax+b
        public static void LinearRegresion(SLValueList list, ref double a, ref double b)
        {
            SLValueList newlist = new SLValueList();
            double      sumax   = 0;
            double      suma2x  = 0;
            double      sumaxy  = 0;
            double      sumay   = 0;
            double      suma2y  = 0;
            double      prumx   = 0;
            double      prumy   = 0;


            for (int i = 0; i < list.Count; i++)
            {
                SLValueXY val = list[i];
                sumax  += val.X;
                suma2x += val.X * val.X;
                sumay  += val.Y;
                suma2y += val.Y * val.Y;
                sumaxy += val.X * val.Y;
            }

            prumx = sumax / list.Count;
            prumy = sumay / list.Count;

            double sx  = (1 / (float)list.Count * suma2x) - prumx * prumx;
            double sy  = (1 / (float)list.Count * suma2y) - prumy * prumy;
            double sxy = (1 / (float)list.Count * sumaxy) - prumx * prumy;

            b = sxy / sx;
            a = prumy - b * prumx;
        }
示例#2
0
        // prida dalsi polozku k datum
        public int Add(SLValueList data)
        {
            int idx    = base.Add(data);
            int zbytek = idx % FunctionClr.Length;

            data.ColorLine  = FunctionClr[zbytek];
            data.ColorPoint = FunctionClr[zbytek];
            return(idx);
        }
示例#3
0
        //lepsi nez EveluateFce
        // lze parametrizovat
        // --------------------
        public SLValueList EvalFunction(string expr, double xfrom, double xto, double step)
        {
            if (xfrom >= xto)
            {
                return(null);
            }
            if ((xto - xfrom) < step)
            {
                return(null);
            }

            SLValueList newdata = new SLValueList();

            newdata.Title  = expr;
            math.Expresion = expr;
            MathVar var;

            var = math.Get("x");
            if (var == null)
            {
                var = math.AddVariable("x", 0);
            }

            for (double i = xfrom; i < xto + step; i += (double)step)
            {
                if (Math.Abs(i) < 0.00001)
                {
                    i = 0;
                }

                i         = Math.Round(i, 5);
                var.value = i;
                double    x   = i;
                double    y   = math.Evaluate();
                SLValueXY val = new SLValueXY();
                val.X = x;
                val.Y = y;
                newdata.Add(val);
            }

            //Add(newdata);
            return(newdata);
        }
示例#4
0
        public static SLValueList EvalPolarFce(string xexpr, string yexpr, double from, double to, double step)
        {
            if (from >= to)
            {
                return(null);
            }
            if ((to - from) < step)
            {
                return(null);
            }

            SLValueList newdata = new SLValueList();

            SLMath.SLMathExp mathx = new SLMathExp();
            SLMath.SLMathExp mathy = new SLMathExp();
            mathx.Expresion = xexpr;
            mathy.Expresion = yexpr;
            MathVar var1 = mathx.AddVariable("x", 0);
            MathVar var2 = mathy.AddVariable("x", 0);

            for (double i = from; i < to + step; i += (double)step)
            {
                if (Math.Abs(i) < 0.00001)
                {
                    i = 0;
                }

                i          = Math.Round(i, 5);
                var1.value = i;
                var2.value = i;
                double    x   = mathx.Evaluate();
                double    y   = mathy.Evaluate();
                SLValueXY val = new SLValueXY();
                val.X = x;
                val.Y = y;
                newdata.Add(val);
            }

            //Add(newdata);
            return(newdata);
        }
示例#5
0
 // smaze polozku
 public void Remove(SLValueList data)
 {
     base.Remove(data);
 }
示例#6
0
 // prida polozku
 public void Insert(int index, SLValueList data)
 {
     base.Insert(index, data);
 }
示例#7
0
文件: slgaus.cs 项目: msvoboda/slgaus
        //*********** kresleni dat **********
        protected void PaintDataList(PaintEventArgs e)
        {
            for (int i = 0; i < DataList.Count; i++)
            {
                SLMath.SLValueList ValueList = DataList[i];
                int     navic   = 3 - (ValueList.Count - 4) % 3;
                Point[] points  = new Point[ValueList.Count + navic];
                Pen     barva   = new Pen(ValueList.ColorLine);
                Brush   BrBarva = new SolidBrush(ValueList.ColorLine);

                if (ValueList.ShowPoints == false && ValueList.ShowLine == false)
                {
                    continue;
                }

                for (int j = 0; j < ValueList.Count; j++)
                {
                    //int pocetF = ValueList.Count;
                    SLMath.SLValueXY valXY = (SLMath.SLValueXY)ValueList[j];
                    if (valXY.isValid() == false)
                    {
                        continue;
                    }


                    int bodX1 = (int)(x_abs((float)valXY.X));
                    int bodY1 = (int)(y_abs((float)valXY.Y));

                    points[j] = new Point(bodX1, bodY1);

                    if (j == ValueList.Count - 1)
                    {
                        for (int c = 0; c < navic; c++)
                        {
                            points[ValueList.Count + c] = new Point(bodX1, bodY1);
                        }
                    }

                    // kresli kolecka ... pokud najedeme mysi na bod

                    /*
                     * if ((RealMouseX >= (float)valXY.X-0.1 && RealMouseX <= (float)valXY.X+0.1) && (RealMouseY >= (float)valXY.Y-0.1 && RealMouseY <= (float)valXY.Y+0.1))
                     *      e.Graphics.FillEllipse(BrBarva,bodX1-ValueList.PointSize-1,bodY1-ValueList.PointSize-1,2*ValueList.PointSize+2,2*ValueList.PointSize+2);*/
                    //
                    if (ValueList.ShowPoints == true)
                    {
                        if (ValueList.PointStyle == SLMath.SLValueList.PointStyles.Cross)
                        {
                            e.Graphics.DrawLine(barva, bodX1 - ValueList.PointSize, bodY1, bodX1 + ValueList.PointSize, bodY1);
                            e.Graphics.DrawLine(barva, bodX1, bodY1 - ValueList.PointSize, bodX1, bodY1 + ValueList.PointSize);
                        }
                        if (ValueList.PointStyle == SLMath.SLValueList.PointStyles.Circle)
                        {
                            e.Graphics.FillEllipse(BrBarva, bodX1 - ValueList.PointSize, bodY1 - ValueList.PointSize, 2 * ValueList.PointSize + 1, 2 * ValueList.PointSize + 1);
                        }
                        if (ValueList.PointStyle == SLMath.SLValueList.PointStyles.Cube)
                        {
                            e.Graphics.FillRectangle(BrBarva, bodX1 - ValueList.PointSize, bodY1 - ValueList.PointSize, ValueList.PointSize * 2 + 1, ValueList.PointSize * 2 + 1);
                        }
                        if (ValueList.PointStyle == SLMath.SLValueList.PointStyles.Diamond)
                        {
                            // Create points that define polygon.
                            Point   point1     = new Point(bodX1 - ValueList.PointSize, bodY1);
                            Point   point2     = new Point(bodX1, bodY1 - ValueList.PointSize);
                            Point   point3     = new Point(bodX1 + ValueList.PointSize, bodY1);
                            Point   point4     = new Point(bodX1, bodY1 + ValueList.PointSize);
                            Point[] diamPoints = { point1, point2, point3, point4 };
                            // Draw polygon to screen.
                            e.Graphics.FillPolygon(BrBarva, diamPoints);
                        }
                        if (ValueList.PointStyle == SLMath.SLValueList.PointStyles.Triangle)
                        {
                            // Create points that define polygon.
                            Point   point1    = new Point(bodX1 - (2 * ValueList.PointSize / 3) - 1, (bodY1 + ValueList.PointSize / 3) + 1);
                            Point   point2    = new Point(bodX1 + (2 * ValueList.PointSize / 3) + 1, (bodY1 + ValueList.PointSize / 3) + 1);
                            Point   point3    = new Point(bodX1, (bodY1 - 2 * ValueList.PointSize / 3) - 1);
                            Point   point4    = new Point(bodX1 - (2 * ValueList.PointSize / 3) - 1, (bodY1 + ValueList.PointSize / 3) - 1);
                            Point[] tryPoints = { point1, point2, point3, point4 };
                            // Draw polygon to screen.
                            e.Graphics.FillPolygon(BrBarva, tryPoints);
                        }
                    }

                    /*
                     * if (ValueList.ShowLine == true)
                     * {
                     *      if (ValueList.AproxStyle == SLMath.SLValueList.AproximationStyles.aLine)
                     *      {
                     *              e.Graphics.DrawLine(barva,bodX1,bodY1,bodX2,bodY2);
                     *      }
                     *      if (ValueList.AproxStyle == SLMath.SLValueList.AproximationStyles.aBezier)
                     *      {
                     *
                     *      }
                     * }*/
                }
                if (ValueList.ShowLine == true)
                {
                    if (ValueList.AproxStyle == SLMath.SLValueList.AproximationStyles.aLine)
                    {
                        e.Graphics.DrawLines(barva, points);
                    }
                    if (ValueList.AproxStyle == SLMath.SLValueList.AproximationStyles.aBezier)
                    {
                        e.Graphics.DrawBeziers(barva, points);
                    }
                    if (ValueList.AproxStyle == SLMath.SLValueList.AproximationStyles.aSpline)
                    {
                        e.Graphics.DrawCurve(barva, points);
                    }
                }
            }
        }
示例#8
0
文件: slgaus.cs 项目: msvoboda/slgaus
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            ///Font a = new Font("Arial", 10);
            Brush black   = System.Drawing.SystemBrushes.WindowText;
            Brush podklad = new SolidBrush(this.BackColor);
            Pen   gridPen = new Pen(color_Grid, 1);

            gridPen.DashStyle = GridStyle;
            Pen pen  = new Pen(System.Drawing.Color.Black, Axis_W);
            Pen blue = System.Drawing.Pens.Blue;

            // LEGENDA KE GRAFU
            // vypocet maximalni sirky legendy
            if (m_showlegend == true)
            {
                SizeF sizel = new SizeF(0, 0);
                SizeF tm;
                for (int i = 0; i < DataList.Count; i++)
                {
                    SLMath.SLValueList ValueList = DataList[i];
                    tm = e.Graphics.MeasureString(ValueList.Title, AxisFont);
                    if (tm.Width > sizel.Width)
                    {
                        sizel = tm;
                    }
                }
                m_rmargin = ((int)sizel.Width) + 20;
                TransformXY(Max_X, Min_X, Max_Y, Min_Y);
            }

            e.Graphics.FillRectangle(podklad, e.ClipRectangle);
            //e.Graphics.DrawString(Title, a,black,10,10);
            e.Graphics.DrawLine(pen, Relative0_X, m_tmargin, Relative0_X, this.Height - m_bmargin);           //y
            e.Graphics.DrawLine(pen, m_lmargin, Relative0_Y, this.Width - m_rmargin, Relative0_Y);            //x

            // zobrazeni titulku
            if (m_title.Length != 0)
            {
                e.Graphics.DrawString(m_title, Font, new SolidBrush(ForeColor), x_abs(Min_X), 3);
            }
            // zobrazeni popisku osy x
            if (m_axisx.Length != 0)
            {
                SizeF del = e.Graphics.MeasureString(m_axisx, AxisFont);
                e.Graphics.DrawString(m_axisx, AxisFont, black, x_abs(0) - del.Width / 2, y_abs(Min_Y) + 5);
            }
            if (m_axisy.Length != 0)
            {
                StringFormat StrForm = new StringFormat();
                SizeF        del     = e.Graphics.MeasureString(m_axisx, AxisFont);
                StrForm.FormatFlags = StringFormatFlags.DirectionVertical;
                e.Graphics.DrawString(m_axisy, AxisFont, black, x_abs(Min_X) - del.Height - 8, y_abs(0) - del.Width / 2, StrForm);
            }
            // zobrazeni legendy
            if (m_showlegend == true)
            {
                for (int i = 0; i < DataList.Count; i++)
                {
                    SLMath.SLValueList ValueList = DataList[i];
                    Pen   legpen = new Pen(ValueList.ColorLine, 2);
                    SizeF posun  = e.Graphics.MeasureString("A", AxisFont);
                    e.Graphics.DrawLine(legpen, x_abs(this.Max_X) + 6, y_abs(this.Max_Y) + posun.Height / 2 + (posun.Height + 2) * i, x_abs(this.Max_X) + 12, y_abs(this.Max_Y) + posun.Height / 2 + (posun.Height + 2) * i);
                    e.Graphics.DrawString(ValueList.Title, AxisFont, black, x_abs(this.Max_X) + 15, y_abs(this.Max_Y) + (posun.Height + 2) * i);
                }
            }
            //grid ////////////
            if (GRID_Y == true)
            {
                for (float r = 0 + Step_Y; r <= Max_Y; r += Step_Y)
                {
                    e.Graphics.DrawLine(gridPen, m_lmargin, y_abs(r), this.Width - m_rmargin, y_abs(r));
                    //string hodnota = r.ToString();
                    //e.Graphics.DrawString(hodnota, a,black,Relative0_X + 10, y_abs(r)- m_margin);
                }

                for (float r = 0 - Step_Y; r >= Min_Y; r -= Step_Y)
                {
                    e.Graphics.DrawLine(gridPen, m_lmargin, y_abs(r), this.Width - m_rmargin, y_abs(r));
                    //string hodnota = r.ToString();
                    //e.Graphics.DrawString(hodnota, a,black,Relative0_X +10, y_abs(r)- m_margin);
                }
            }
            if (GRID_X == true)
            {
                for (float s = 0 + Step_X; s <= Max_X; s += Step_X)
                {
                    e.Graphics.DrawLine(gridPen, x_abs(s), m_tmargin, x_abs(s), this.Height - m_bmargin);
                    //string hodnota = s.ToString();
                    //e.Graphics.DrawString(hodnota, a,black, x_abs(s)-m_margin,Relative0_Y + 10);
                }

                for (float s = 0 - Step_X; s >= Min_X; s -= Step_X)
                {
                    e.Graphics.DrawLine(gridPen, x_abs(s), m_tmargin, x_abs(s), this.Height - m_bmargin);
                    //string hodnota = s.ToString();
                    //e.Graphics.DrawString(hodnota, a,black, x_abs(s)- m_margin,Relative0_Y + 10);
                }
            }
            ////////////////////////

            //popis os ///////////////////////

            for (float s = 0; s <= Max_X; s += Step_X)
            {
                e.Graphics.DrawLine(pen, x_abs(s), Relative0_Y - 3, x_abs(s), Relative0_Y + 3);
                string hodnota = s.ToString();
                e.Graphics.DrawString(hodnota, AxisFont, black, x_abs(s) - m_axmargin, Relative0_Y + 5);
            }

            for (float s = 0 - Step_X; s >= Min_X; s -= Step_X)
            {
                e.Graphics.DrawLine(pen, x_abs(s), Relative0_Y - 3, x_abs(s), Relative0_Y + 3);
                string hodnota = s.ToString();
                e.Graphics.DrawString(hodnota, AxisFont, black, x_abs(s) - m_axmargin, Relative0_Y + 5);
            }

            for (float r = 0 + Step_Y; r <= Max_Y; r += Step_Y)
            {
                e.Graphics.DrawLine(pen, Relative0_X - 3, y_abs(r), Relative0_X + 3, y_abs(r));
                string hodnota = r.ToString();
                e.Graphics.DrawString(hodnota, AxisFont, black, Relative0_X + 10, y_abs(r) - m_axmargin);
            }

            for (float r = 0 - Step_Y; r >= Min_Y; r -= Step_Y)
            {
                e.Graphics.DrawLine(pen, Relative0_X - 3, y_abs(r), Relative0_X + 3, y_abs(r));
                string hodnota = r.ToString();
                e.Graphics.DrawString(hodnota, AxisFont, black, Relative0_X + 10, y_abs(r) - m_axmargin);
            }
            ////////////////////////////////
            // kresleni dat
            PaintDataList(e);
            //
            if (m_showxy == true)
            {
                System.Globalization.NumberFormatInfo nfi = new System.Globalization.CultureInfo("en-US", false).NumberFormat;
                nfi.NumberDecimalDigits = 2;
                string xy  = "x=" + RealMouseX.ToString("N", nfi) + "\ny=" + RealMouseY.ToString("N", nfi);
                Font   fnt = new Font("Verdana", 8);
                e.Graphics.DrawString(xy, fnt, black, x_abs(this.Min_X) + 6, y_abs(this.Min_Y) + 2);
            }
        }
示例#9
0
        public static SLValueList DerivateFce(SLValueList Fx)
        {
            SLValueList newdata = new SLValueList();

            for (int k = 0; k < Fx.Count - 1; k++)
            {
                SLValueXY val1   = (SLMath.SLValueXY)Fx[k];
                SLValueXY val2   = (SLMath.SLValueXY)Fx[k + 1];
                SLValueXY newval = new SLValueXY();

                float krok = (float)val2.X - (float)val1.X;
                newval.X = val1.X;
                newval.Y = ((float)val2.Y - (float)val1.Y) / krok;               //!!!!!!!!!!


                newdata.Add(newval);
            }
            return(newdata);

            /*double point = System.Convert.ToDouble(bod.Text);
             * double krok1 = System.Convert.ToDouble(k1.Text);
             * double krok2 = System.Convert.ToDouble(k2.Text);
             * double krok3 = System.Convert.ToDouble(k3.Text);
             * double krok4 = System.Convert.ToDouble(k4.Text);
             * double krok5 = System.Convert.ToDouble(k5.Text);
             * double[] prok1 = new double[2];
             * double[] prok2 = new double[2];
             * double[] prok3 = new double[2];
             * double[] prok4 = new double[2];
             * double[] prok5 = new double[2];
             *
             *
             * if (puntik1.Checked == true)    // dvoubodovka prvni derivace
             * {
             *      prok1[0] = (Fce(point+krok1) - Fce(point))/krok1;
             *      prok2[0] = (Fce(point+krok2) - Fce(point))/krok2;
             *      prok3[0] = (Fce(point+krok3) - Fce(point))/krok3;
             *      prok4[0] = (Fce(point+krok4) - Fce(point))/krok4;
             *      prok5[0] = (Fce(point+krok5) - Fce(point))/krok5;
             * }
             *
             * if (puntik2.Checked == true)    // tribodovka prvni derivace
             * {
             *      prok1[0] = (-3*Fce(point) + 4*Fce(point+krok1) - Fce(point+2*krok1))/2*krok1;
             *      prok2[0] = (-3*Fce(point) + 4*Fce(point+krok2) - Fce(point+2*krok2))/2*krok2;
             *      prok3[0] = (-3*Fce(point) + 4*Fce(point+krok3) - Fce(point+2*krok3))/2*krok3;
             *      prok4[0] = (-3*Fce(point) + 4*Fce(point+krok4) - Fce(point+2*krok4))/2*krok4;
             *      prok5[0] = (-3*Fce(point) + 4*Fce(point+krok5) - Fce(point+2*krok5))/2*krok5;
             * }
             *
             * if (puntik3.Checked == true)    // ctyrbodovka prvni derivace
             * {
             *      prok1[0] = (-11*Fce(point) + 18*Fce(point+krok1) - 9*Fce(point+2*krok1) + 2*Fce(point+3*krok1))/6*krok1;
             *      prok2[0] = (-11*Fce(point) + 18*Fce(point+krok2) - 9*Fce(point+2*krok2) + 2*Fce(point+3*krok2))/6*krok2;
             *      prok3[0] = (-11*Fce(point) + 18*Fce(point+krok3) - 9*Fce(point+2*krok3) + 2*Fce(point+3*krok3))/6*krok3;
             *      prok4[0] = (-11*Fce(point) + 18*Fce(point+krok4) - 9*Fce(point+2*krok4) + 2*Fce(point+3*krok4))/6*krok4;
             *      prok5[0] = (-11*Fce(point) + 18*Fce(point+krok5) - 9*Fce(point+2*krok5) + 2*Fce(point+3*krok5))/6*krok5;
             * }
             *
             * if (puntik4.Checked == true)    // petibodovka prvni derivace
             * {
             *      prok1[0] = (-25*Fce(point) + 48*Fce(point+krok1) - 36*Fce(point+2*krok1) + 16*Fce(point+3*krok1) - 3*Fce(point+4*krok1))/12*krok1;
             *      prok2[0] = (-25*Fce(point) + 48*Fce(point+krok2) - 36*Fce(point+2*krok2) + 16*Fce(point+3*krok2) - 3*Fce(point+4*krok2))/12*krok2;
             *      prok3[0] = (-25*Fce(point) + 48*Fce(point+krok3) - 36*Fce(point+2*krok3) + 16*Fce(point+3*krok3) - 3*Fce(point+4*krok3))/12*krok3;
             *      prok4[0] = (-25*Fce(point) + 48*Fce(point+krok4) - 36*Fce(point+2*krok4) + 16*Fce(point+3*krok4) - 3*Fce(point+4*krok4))/12*krok4;
             *      prok5[0] = (-25*Fce(point) + 48*Fce(point+krok5) - 36*Fce(point+2*krok5) + 16*Fce(point+3*krok5) - 3*Fce(point+4*krok5))/12*krok5;
             * }
             *
             * if (puntik5.Checked == true)    // tribodovka druha derivace
             * {
             *      prok1[1] = (Fce(point) - 2*Fce(point+krok1) + Fce(point+2*krok1))/krok1*krok1;
             *      prok2[1] = (Fce(point) - 2*Fce(point+krok2) + Fce(point+2*krok2))/krok2*krok2;
             *      prok3[1] = (Fce(point) - 2*Fce(point+krok3) + Fce(point+2*krok3))/krok3*krok3;
             *      prok4[1] = (Fce(point) - 2*Fce(point+krok4) + Fce(point+2*krok4))/krok4*krok4;
             *      prok5[1] = (Fce(point) - 2*Fce(point+krok5) + Fce(point+2*krok5))/krok5*krok5;
             * }
             *
             * if (puntik6.Checked == true)    // ctyrbodovka druha derivace
             * {
             *      prok1[1] = (2*Fce(point) - 5*Fce(point+krok1) + 4*Fce(point+2*krok1) + Fce(point+3*krok1))/krok1*krok1;
             *      prok2[1] = (2*Fce(point) - 5*Fce(point+krok2) + 4*Fce(point+2*krok2) + Fce(point+3*krok2))/krok2*krok2;
             *      prok3[1] = (2*Fce(point) - 5*Fce(point+krok3) + 4*Fce(point+2*krok3) + Fce(point+3*krok3))/krok3*krok3;
             *      prok4[1] = (2*Fce(point) - 5*Fce(point+krok4) + 4*Fce(point+2*krok4) + Fce(point+3*krok4))/krok4*krok4;
             *      prok5[1] = (2*Fce(point) - 5*Fce(point+krok5) + 4*Fce(point+2*krok5) + Fce(point+3*krok5))/krok5*krok5;
             * }
             *
             *
             *
             * v1.Text = prok1[0].ToString();
             * v2.Text = prok2[0].ToString();
             * v3.Text = prok3[0].ToString();
             * v4.Text = prok4[0].ToString();
             * v5.Text = prok5[0].ToString();
             * v6.Text = prok1[1].ToString();
             * v7.Text = prok2[1].ToString();
             * v8.Text = prok3[1].ToString();
             * v9.Text = prok4[1].ToString();
             * v10.Text = prok5[1].ToString();*/
        }