Ejemplo n.º 1
0
        private void AddData()
        {
            double[] x0 = new double[8];
            double[] y0 = new double[8];
            double[] x  = new double[70];

            for (int i = 0; i < x0.Length; i++)
            {
                x0[i] = 1.0 * i;
                y0[i] = Math.Sin(x0[i]);
            }

            for (int i = 0; i < x.Length; i++)
            {
                x[i] = i / 10.0;
            }

            double[] y = InterpolationAlgorithms.Lagrangian(x0, y0, x);

            myChart.DataCollection.DataList.Clear();

            // plot interpolated data:
            LineCharts.DataSeries ds = new LineCharts.DataSeries();
            ds.LineColor           = Brushes.Transparent;
            ds.SeriesName          = "Interpolated";
            ds.Symbols.SymbolType  = LineCharts.Symbols.SymbolTypeEnum.Dot;
            ds.Symbols.SymbolSize  = 3;
            ds.Symbols.BorderColor = Brushes.Red;
            for (int i = 0; i < x.Length; i++)
            {
                ds.LineSeries.Points.Add(new Point(x[i], y[i]));
            }
            myChart.DataCollection.DataList.Add(ds);


            // Plot original data
            ds                     = new LineCharts.DataSeries();
            ds.LineColor           = Brushes.Transparent;
            ds.SeriesName          = "Original";
            ds.Symbols.SymbolType  = LineCharts.Symbols.SymbolTypeEnum.Diamond;
            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);
            myChart.IsLegend       = true;
            myChart.LegendPosition = LineCharts.Legend.LegendPositionEnum.NorthEast;
        }
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 };
            double[] y0 = new double[] { 1, 5, 4 };
            double[] x  = new double[199];
            for (int i = 0; i < x.Length; i++)
            {
                x[i] = 1.01 + i / 100.0;
            }
            double[] y = InterpolationAlgorithms.Spline(x0, y0, x);

            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.Dot;
            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);

            // plot interpolated data:
            ds            = new LineCharts.DataSeries();
            ds.LineColor  = Brushes.DarkGreen;
            ds.SeriesName = "Interpolated";
            for (int i = 0; i < x.Length; i++)
            {
                ds.LineSeries.Points.Add(new Point(x[i], y[i]));
            }
            myChart.DataCollection.DataList.Add(ds);

            myChart.IsLegend       = true;
            myChart.LegendPosition = LineCharts.Legend.LegendPositionEnum.NorthWest;
        }
Ejemplo n.º 4
0
        private void AddData()
        {
            myLineChart.DataCollection.DataList.Clear();

            // Draw Sine curve:
            LineCharts.DataSeries ds = new LineCharts.DataSeries();
            ds.LineColor           = Brushes.Blue;
            ds.LineThickness       = 1;
            ds.SeriesName          = "Sine";
            ds.Symbols.SymbolType  = LineCharts.Symbols.SymbolTypeEnum.Circle;
            ds.Symbols.BorderColor = ds.LineColor;
            for (int i = 0; i < 70; i++)
            {
                double x = i / 5.0;
                double y = Math.Sin(x);
                ds.LineSeries.Points.Add(new Point(x, y));
            }
            myLineChart.DataCollection.DataList.Add(ds);

            // Draw cosine curve:
            ds                     = new LineCharts.DataSeries();
            ds.LineColor           = Brushes.Red;
            ds.SeriesName          = "Cosine";
            ds.Symbols.SymbolType  = LineCharts.Symbols.SymbolTypeEnum.OpenDiamond;
            ds.Symbols.BorderColor = ds.LineColor;
            ds.LinePattern         = LineCharts.DataSeries.LinePatternEnum.DashDot;
            ds.LineThickness       = 2;
            for (int i = 0; i < 70; i++)
            {
                double x = i / 5.0;
                double y = Math.Cos(x);
                ds.LineSeries.Points.Add(new Point(x, y));
            }
            myLineChart.DataCollection.DataList.Add(ds);

            myLineChart.IsLegend       = true;
            myLineChart.LegendPosition = LineCharts.Legend.LegendPositionEnum.NorthEast;
        }
        private void LinearScale(double[] x0, double[] y0, double[] results)
        {
            linearChart.DataCollection.DataList.Clear();
            LineCharts.DataSeries ds;

            linearChart.ChartStyle.Ymin   = -50;
            linearChart.ChartStyle.Ymax   = 350;
            linearChart.ChartStyle.YTick  = 50;
            linearChart.ChartStyle.YLabel = "Y";

            // 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]));
            }
            linearChart.DataCollection.DataList.Add(ds);

            // Plot curve fittin data:
            ds               = new LineCharts.DataSeries();
            ds.LineColor     = Brushes.DarkGreen;
            ds.LineThickness = 2;
            ds.SeriesName    = "Curve Fitting";
            for (int i = 0; i < 111; i++)
            {
                double x = 0.1 + i / 10.0;
                double y = Math.Exp(results[0] + results[1] * x);
                ds.LineSeries.Points.Add(new Point(x, y));
            }
            linearChart.DataCollection.DataList.Add(ds);

            linearChart.Legend.IsLegend       = true;
            linearChart.Legend.LegendPosition = LineCharts.Legend.LegendPositionEnum.NorthWest;
        }
        private void AddData()
        {
            double[] x0 = new double[] { 1950, 1960, 1970, 1980, 1990 };
            double[] y0 = new double[] { 150.697, 179.323, 203.212, 226.505, 249.633 };
            double[] x  = new double[] { 1952, 1955, 1958, 1962, 1965, 1968, 1972, 1975, 1978, 1982, 1985, 1988 };
            double[] y  = InterpolationAlgorithms.NewtonDividedDifference(x0, y0, x);

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

            // plot interpolated data:
            ds                     = new LineCharts.DataSeries();
            ds.LineColor           = Brushes.Transparent;
            ds.SeriesName          = "Interpolated";
            ds.Symbols.SymbolType  = LineCharts.Symbols.SymbolTypeEnum.Circle;
            ds.Symbols.BorderColor = Brushes.Red;
            for (int i = 0; i < x.Length; i++)
            {
                ds.LineSeries.Points.Add(new Point(x[i], y[i]));
            }
            myChart.DataCollection.DataList.Add(ds);

            // Plot original data
            ds                     = new LineCharts.DataSeries();
            ds.LineColor           = Brushes.DarkGreen;
            ds.SeriesName          = "Original";
            ds.Symbols.SymbolType  = LineCharts.Symbols.SymbolTypeEnum.Dot;
            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);
            myChart.IsLegend       = true;
            myChart.LegendPosition = LineCharts.Legend.LegendPositionEnum.NorthWest;
        }
        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.º 8
0
        /*
         * Constructor for graph window
         * Goes through the values in both the income and expenses lists associated with the current user
         * plots datapoints on two separate graphs depending on which list they come from
         *
         * May want to update the X axis in the future. Currently the x axis doesn't really make much sense to a lay person
         * but the income x-axis is used for pay periods. The x-axis for expenses should just sync up with the income axis.
         * The expenses x-axis is number of expenditures during the number of pay periods listed in the income graph x-axis
         *
         * */
        public Graph(List <MoneyData> expenses, List <MoneyData> income)
        {
            this.income   = income;
            this.expenses = expenses;
            InitializeComponent();

            if (expenses.Count > 0)
            {
                double Xmax = 0;     // adjusted max values
                double Ymax = 0;
                LineCharts.DataSeries ds = new LineCharts.DataSeries();
                ds.LineColor          = Brushes.Orange;
                ds.LineThickness      = 1;
                ds.SeriesName         = "Expenses";
                ds.Symbols.SymbolType = LineCharts.Symbols.SymbolTypeEnum.Circle;
                Expenses.OriginalData.DataList.Add(ds);
                //Graph expenses on expenses graph
                for (int i = 0; i < expenses.Count; i++)
                {
                    double x = i;
                    double y = expenses[i].Amount;
                    if (Xmax < x)
                    {
                        Xmax = x;
                    }
                    if (Ymax < y)
                    {
                        Ymax = y;
                    }

                    ds.LineSeries.Points.Add(new Point(x, y));
                }
                Expenses.Ymax  = Ymax * 1.1;
                Expenses.Ymin  = 0;
                Expenses.YTick = (Expenses.Ymax - Expenses.Ymin) / 10;
                Expenses.Xmin  = 0;
                Expenses.Xmax  = Xmax;
                Expenses.XTick = (Expenses.Xmax - Expenses.Xmin) / 10;



                Expenses.Refresh(); //Refreshes the graph to show changes
            }
            if (income.Count > 0)
            {
                double Xmax = 0; // adjusted max values
                double Ymax = 0;
                LineCharts.DataSeries ds = new LineCharts.DataSeries();
                ds.LineColor          = Brushes.Orange;
                ds.LineThickness      = 1;
                ds.SeriesName         = "Income";
                ds.Symbols.SymbolType = LineCharts.Symbols.SymbolTypeEnum.Circle;
                Income.OriginalData.DataList.Add(ds);
                for (int i = 0; i < income.Count; i++)
                {
                    double x = i;
                    double y = income[i].Amount;
                    if (Xmax < x)
                    {
                        Xmax = x;
                    }
                    if (Ymax < y)
                    {
                        Ymax = y;
                    }
                    ds.LineSeries.Points.Add(new Point(x, y));
                }
                Income.Ymax  = Ymax * 1.1;
                Income.Ymin  = 0;
                Income.YTick = (Expenses.Ymax - Income.Ymin) / 10;
                Income.Xmin  = 0;
                Income.Xmax  = Xmax;
                Income.XTick = (Expenses.Xmax - Income.Xmin) / 10;
                //Graph income on income graph
                Income.Refresh(); //Refreshes the graph to show changes
            }
        }
Ejemplo n.º 9
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;
        }
        private void AddData()
        {
            double[] x0 = new double[15];
            double[] y0 = new double[15];
            double[] xe = new double[101];
            double[] ye = new double[101];

            double[] x = new double[31];


            for (int i = 0; i < x0.Length; i++)
            {
                x0[i] = Math.Round(-1.2 + i / 5.0, 3);
                y0[i] = Math.Round(Math.Sin(8 * x0[i]) + 0.5 * x0[i] - x0[i] * x0[i], 2);
            }

            for (int i = 0; i < xe.Length; i++)
            {
                xe[i] = Math.Round(-1.0 + i / 50.0, 3);
                ye[i] = Math.Round(Math.Sin(8 * xe[i]) + 0.5 * xe[i] - xe[i] * xe[i], 2);
            }

            for (int i = 0; i < x.Length; i++)
            {
                x[i] = Math.Round(-1.0 + i / 15.0, 3);
            }

            double[] y = InterpolationAlgorithms.Lagrangian(x0, y0, x);

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

            // Plot exact data:
            ds            = new LineCharts.DataSeries();
            ds.LineColor  = Brushes.DarkGreen;
            ds.SeriesName = "Exact";
            for (int i = 1; i < xe.Length - 1; i++)
            {
                ds.LineSeries.Points.Add(new Point(xe[i], ye[i]));
            }
            myChart.DataCollection.DataList.Add(ds);

            // plot interpolated data:
            ds                     = new LineCharts.DataSeries();
            ds.LineColor           = Brushes.Transparent;
            ds.SeriesName          = "Interpolated";
            ds.Symbols.SymbolType  = LineCharts.Symbols.SymbolTypeEnum.Circle;
            ds.Symbols.BorderColor = Brushes.Red;
            for (int i = 1; i < x.Length - 1; i++)
            {
                ds.LineSeries.Points.Add(new Point(x[i], y[i]));
            }
            myChart.DataCollection.DataList.Add(ds);

            // Plot original data
            ds                     = new LineCharts.DataSeries();
            ds.LineColor           = Brushes.Transparent;
            ds.SeriesName          = "Original";
            ds.Symbols.SymbolType  = LineCharts.Symbols.SymbolTypeEnum.Dot;
            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);
            myChart.IsLegend       = true;
            myChart.LegendPosition = LineCharts.Legend.LegendPositionEnum.NorthWest;
        }