private void AddData()
        {
            double[] x0   = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            double[] y0   = new double[] { 1.9398, 2.9836, 5.9890, 10.2, 20.7414, 23.232, 69.5855, 82.5836, 98.1779, 339.3256 };
            double[] ylog = new double[] { 0.6626, 1.0931, 1.7899, 2.3224, 3.0321, 3.1455, 4.2426, 4.4138, 4.5868, 5.8270 };

            double[] results = CurveFittingAlgorithms.WeightedLinearRegression(x0, ylog, y0);

            // Plot linear scale results:
            LinearScale(x0, y0, results);

            // Plot log scale results:
            LogScale(x0, ylog, results);
        }
Ejemplo n.º 2
0
        private void AddData()
        {
            double[] x0      = new double[] { 0, 1, 2, 3, 4, 5 };
            double[] y0      = new double[] { 1.9, 2.7, 3.3, 4.4, 5.5, 6.5 };
            double[] results = CurveFittingAlgorithms.StraightLineFit(x0, y0);

            myChart.DataCollection.DataList.Clear();
            LineCharts.DataSeries ds;

            // Plot original data
            ds                     = new LineCharts.DataSeries();
            ds.LineColor           = Brushes.Transparent;
            ds.SeriesName          = "Original";
            ds.Symbols.SymbolType  = LineCharts.Symbols.SymbolTypeEnum.OpenTriangle;
            ds.Symbols.BorderColor = Brushes.DarkBlue;
            for (int i = 0; i < x0.Length; i++)
            {
                ds.LineSeries.Points.Add(new Point(x0[i], y0[i]));
            }
            myChart.DataCollection.DataList.Add(ds);

            // Curve fitting data:
            ds            = new LineCharts.DataSeries();
            ds.LineColor  = Brushes.DarkGreen;
            ds.SeriesName = "Curve Fitting";
            for (int i = 0; i < 101; i++)
            {
                double x = i / 20.0;
                double y = results[0] + results[1] * x;
                ds.LineSeries.Points.Add(new Point(x, y));
            }
            myChart.DataCollection.DataList.Add(ds);

            myChart.IsLegend       = true;
            myChart.LegendPosition = LineCharts.Legend.LegendPositionEnum.NorthWest;

            //MessageBox.Show(results[0].ToString() + ", " +
            //    results[1].ToString() + ", " +
            //    results[2].ToString() + ", ");
        }
        private void AddData()
        {
            double[] x0 = new double[] { 1, 2, 3, 4, 5 };
            double[] y0 = new double[] { 5.5, 43.1, 128, 290.7, 498.4 };

            VectorR[] results = new VectorR[3];

            for (int i = 0; i < results.Length; i++)
            {
                double sigma = 0;
                results[i] = CurveFittingAlgorithms.PolynomialFit(x0, y0, i + 1, out sigma);
            }

            // Plot results:
            myChart.DataCollection.DataList.Clear();
            LineCharts.DataSeries ds;

            // Plot original data:
            ds                     = new LineCharts.DataSeries();
            ds.LineColor           = Brushes.Transparent;
            ds.SeriesName          = "Original";
            ds.Symbols.SymbolType  = LineCharts.Symbols.SymbolTypeEnum.Triangle;
            ds.Symbols.BorderColor = Brushes.Black;
            for (int i = 0; i < x0.Length; i++)
            {
                ds.LineSeries.Points.Add(new Point(x0[i], y0[i]));
            }
            myChart.DataCollection.DataList.Add(ds);

            // 1st order fitting data:
            ds               = new LineCharts.DataSeries();
            ds.LineColor     = Brushes.DarkGreen;
            ds.LineThickness = 2;
            ds.SeriesName    = "1st Order Fitting";
            for (int i = 0; i < 141; i++)
            {
                double x = -1.0 + i / 20.0;
                double y = results[0][0] + results[0][1] * x;
                ds.LineSeries.Points.Add(new Point(x, y));
            }
            myChart.DataCollection.DataList.Add(ds);

            // 2nd order fitting data:
            ds               = new LineCharts.DataSeries();
            ds.LineColor     = Brushes.Red;
            ds.LineThickness = 2;
            ds.LinePattern   = LineCharts.DataSeries.LinePatternEnum.Dash;
            ds.SeriesName    = "2nd Order Fitting";
            for (int i = 0; i < 141; i++)
            {
                double x = -1.0 + i / 20.0;
                double y = results[1][0] + results[1][1] * x + results[1][2] * x * x;
                ds.LineSeries.Points.Add(new Point(x, y));
            }
            myChart.DataCollection.DataList.Add(ds);

            // 3rd order fitting data:
            ds               = new LineCharts.DataSeries();
            ds.LineColor     = Brushes.DarkBlue;
            ds.LineThickness = 2;
            ds.LinePattern   = LineCharts.DataSeries.LinePatternEnum.DashDot;
            ds.SeriesName    = "3rd Order Fitting";
            for (int i = 0; i < 141; i++)
            {
                double x = -1.0 + i / 20.0;
                double y = results[2][0] + results[2][1] * x + results[2][2] * x * x + results[2][3] * x * x * x;
                ds.LineSeries.Points.Add(new Point(x, y));
            }
            myChart.DataCollection.DataList.Add(ds);

            myChart.IsLegend       = true;
            myChart.LegendPosition = LineCharts.Legend.LegendPositionEnum.NorthWest;
        }
Ejemplo n.º 4
0
        private void AddData()
        {
            double[] x0 = new double[] { 0, 1, 2, 3, 4, 5 };
            double[] y0 = new double[] { 2, 1, 4, 4, 3, 2 };

            // First order polynormial (m = 1):
            CurveFittingAlgorithms.ModelFunction[] f = new CurveFittingAlgorithms.ModelFunction[] { f0, f1 };
            double  sigma    = 0.0;
            VectorR results1 = CurveFittingAlgorithms.LinearRegression(x0, y0, f, out sigma);

            // Second order polynormial (m = 2):
            f = new CurveFittingAlgorithms.ModelFunction[] { f0, f1, f2 };
            VectorR results2 = CurveFittingAlgorithms.LinearRegression(x0, y0, f, out sigma);

            // Third order polynormial (m = 3):
            f = new CurveFittingAlgorithms.ModelFunction[] { f0, f1, f2, f3 };
            VectorR results3 = CurveFittingAlgorithms.LinearRegression(x0, y0, f, out sigma);

            // Plot results:
            myChart.DataCollection.DataList.Clear();
            LineCharts.DataSeries ds;

            // Plot original data:
            ds                     = new LineCharts.DataSeries();
            ds.LineColor           = Brushes.Transparent;
            ds.SeriesName          = "Original";
            ds.Symbols.SymbolType  = LineCharts.Symbols.SymbolTypeEnum.Triangle;
            ds.Symbols.BorderColor = Brushes.Black;
            for (int i = 0; i < x0.Length; i++)
            {
                ds.LineSeries.Points.Add(new Point(x0[i], y0[i]));
            }
            myChart.DataCollection.DataList.Add(ds);

            // 1st order fitting data:
            ds               = new LineCharts.DataSeries();
            ds.LineColor     = Brushes.DarkGreen;
            ds.LineThickness = 2;
            ds.SeriesName    = "1st Order Fitting";
            for (int i = 0; i < 141; i++)
            {
                double x = -1.0 + i / 20.0;
                double y = results1[0] + results1[1] * x;
                ds.LineSeries.Points.Add(new Point(x, y));
            }
            myChart.DataCollection.DataList.Add(ds);

            // 2nd order fitting data:
            ds               = new LineCharts.DataSeries();
            ds.LineColor     = Brushes.Red;
            ds.LineThickness = 2;
            ds.LinePattern   = LineCharts.DataSeries.LinePatternEnum.Dash;
            ds.SeriesName    = "2nd Order Fitting";
            for (int i = 0; i < 141; i++)
            {
                double x = -1.0 + i / 20.0;
                double y = results2[0] + results2[1] * x + results2[2] * x * x;
                ds.LineSeries.Points.Add(new Point(x, y));
            }
            myChart.DataCollection.DataList.Add(ds);

            // 3rd order fitting data:
            ds               = new LineCharts.DataSeries();
            ds.LineColor     = Brushes.DarkBlue;
            ds.LineThickness = 2;
            ds.LinePattern   = LineCharts.DataSeries.LinePatternEnum.DashDot;
            ds.SeriesName    = "3rd Order Fitting";
            for (int i = 0; i < 141; i++)
            {
                double x = -1.0 + i / 20.0;
                double y = results3[0] + results3[1] * x + results3[2] * x * x + results3[3] * x * x * x;
                ds.LineSeries.Points.Add(new Point(x, y));
            }
            myChart.DataCollection.DataList.Add(ds);

            myChart.IsLegend       = true;
            myChart.LegendPosition = LineCharts.Legend.LegendPositionEnum.NorthWest;
        }