Ejemplo n.º 1
0
        public double expcalkawielomian(double a, double b, double[] poly, int v)
        {
            var vals = new ChartValues <ObservablePoint>();
            //ofstream plik;
            //string filename("nodes" + std::to_string(v));
            //plik.open(filename);
            double result = 0, x = 0, fx = 0;
            double h = (b - a) / v;

            for (int i = 0; i <= v; i++)
            {
                x  = a + i * h;
                fx = exphorner(x, poly);
                vals.Add(new ObservablePoint(x, fx));
                points.Add(new ObservablePoint(x, fx));
                //plik << x << " " << fx << endl;
                if (i == 0 || i == v)
                {
                    result += fx;
                }
                else if (i % 2 != 0)
                {
                    result += 4 * fx;
                }
                else
                {
                    result += 2 * fx;
                }
            }
            result *= (h / 3);


            nodesPoints.AddRange(vals);
            var pointsToAdd = nodesPoints.GroupBy(y => y.X).Where(c => c.Count() == 1).Select(z => z.First()).OrderBy(w => w.X).ToList();


            values.Add(new ChartValues <ObservablePoint>(pointsToAdd));
            //plik.close();
            return(result);

            /*double simp = 0, blad = 0, s = 0, x = 0;
             * double h = (b - a) / v;
             * for (int i = 1; i <= v; i++)
             * {
             *  x = a + i * h;
             *  blad += exphorner(x - (h / 2), poly);
             *  if (i < v)
             *  {
             *      s += (exphorner(x, poly));
             *  }
             * }
             * return (h / 6)*(exphorner(a, poly) + exphorner(b, poly) + 2 * s + 4 * blad);*/
        }
Ejemplo n.º 2
0
        public SingleKeySizeForm(int size, IEnumerable <XY> points)
        {
            InitializeComponent();
            _size = size;

            var mapper = Mappers.Xy <XY>()
                         .X(model => model.NDouble)
                         .Y(model => model.TotDouble)
                         .Fill(model => model.Y >= ChartValues.GroupBy(p => p.Y)
                               .OrderByDescending(gp => gp.Count()).Select(p => p.Key).FirstOrDefault()
                    ? new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 150, 0))
                    : model.Y < ChartValues.GroupBy(p => p.Y)
                               .OrderByDescending(gp => gp.Count()).Select(p => p.Key).FirstOrDefault()
                    ? new SolidColorBrush(System.Windows.Media.Color.FromRgb(200, 0, 0))
                    : null);

            Charting.For <XY>(mapper);

            ChartValues        = new ChartValues <XY>();
            RegressionValues   = new ChartValues <ObservablePoint>();
            UpperValues        = new ChartValues <ObservablePoint>();
            LowerValues        = new ChartValues <ObservablePoint>();
            NToNValues         = new ChartValues <ObservablePoint>();
            XAxis              = new ChartValues <ObservablePoint>();
            YAxis              = new ChartValues <ObservablePoint>();
            versusChart.Series = new SeriesCollection
            {
                new ScatterSeries
                {
                    Values        = ChartValues,
                    PointGeometry = DefaultGeometries.Diamond
                },
                new LineSeries
                {
                    Values        = RegressionValues,
                    PointGeometry = null,
                    Fill          = Brushes.Transparent,
                    Stroke        = new SolidColorBrush(System.Windows.Media.Color.FromRgb(200, 0, 0))
                },
                new LineSeries
                {
                    Values        = UpperValues,
                    PointGeometry = null,
                    Fill          = Brushes.Transparent,
                    Stroke        = new SolidColorBrush(System.Windows.Media.Color.FromRgb(200, 0, 0))
                },
                new LineSeries
                {
                    Values        = LowerValues,
                    PointGeometry = null,
                    Fill          = Brushes.Transparent,
                    Stroke        = new SolidColorBrush(System.Windows.Media.Color.FromRgb(200, 0, 0))
                },
                new LineSeries
                {
                    Values        = NToNValues,
                    PointGeometry = null,
                    Fill          = Brushes.Transparent,
                    Stroke        = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 0, 200))
                },
                new LineSeries
                {
                    Values        = XAxis,
                    PointGeometry = null,
                    Fill          = Brushes.Transparent,
                    Stroke        = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 0, 0))
                },
                new LineSeries
                {
                    Values        = YAxis,
                    PointGeometry = null,
                    Fill          = Brushes.Transparent,
                    Stroke        = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 0, 0))
                }
            };
            versusChart.DataClick += (sender, point) =>
            {
                var valuePoint = ChartValues.FirstOrDefault(v => v.NDouble == point.X && v.TotDouble == point.Y);
                if (valuePoint != null)
                {
                    Console.WriteLine(valuePoint.ToString());
                    Console.WriteLine("Range: " + _regression.GetPredictionInterval(valuePoint.NDouble, .99));
                }
            };
            versusChart.Zoom = ZoomingOptions.Xy;
            versusChart.DisableAnimations = true;
            versusChart.DataTooltip       = null;
            ChartValues.AddRange(points);

            CalculateRegression();

            graphTabPanel.SelectedIndexChanged += (sender, args) =>
            {
                if (graphTabPanel.SelectedIndex == 1)
                {
                    BuildHistogram();
                }
            };

            Timer = new Timer
            {
                Interval = 10000
            };
            Timer.Tick += (sender, args) => addButton.PerformClick();
        }