예제 #1
0
        public void PlotWave(PlotView view)
        {
            var model = new PlotModel {
            };

            model.Axes.Add(new OxyPlot.Axes.LinearAxis
            {
                Minimum   = -1.0,
                Maximum   = 1.0,
                MajorStep = 0.5,
                Title     = "Amplitude",
            });

            model.Axes.Add(new OxyPlot.Axes.LinearAxis
            {
                Position = OxyPlot.Axes.AxisPosition.Bottom,
                Title    = "Time (s)",
            });

            var series = new FunctionSeries {
            };

            foreach (var p in waveList)
            {
                series.Points.Add(p);
            }

            model.Series.Add(series);
            view.Model = model;
        }
        private static PlotModel CreateSquareWave(int n = 25)
        {
            var plot = new PlotModel {
                Title = "Square wave (Gibbs phenomenon)"
            };

            Func <double, double> f = (x) =>
            {
                double y = 0;
                for (int i = 0; i < n; i++)
                {
                    int j = i * 2 + 1;
                    y += Math.Sin(j * x) / j;
                }
                return(y);
            };

            var fs = new FunctionSeries(f, -10, 10, 0.0001, "sin(x)+sin(3x)/3+sin(5x)/5+...+sin(" + (2 * n - 1) + ")/" + (2 * n - 1));

            plot.Series.Add(fs);
            plot.Subtitle = "n = " + fs.Points.Count;

            plot.Axes.Add(new LinearAxis
            {
                Position = AxisPosition.Left,
                Minimum  = -4,
                Maximum  = 4
            });
            plot.Axes.Add(new LinearAxis
            {
                Position = AxisPosition.Bottom
            });

            return(plot);
        }
예제 #3
0
        private void FillFFTView(PlotView view, double[] result)
        {
            var model = new PlotModel {
            };

            model.Axes.Add(new LinearAxis
            {
                Title = "Amplitude (dB)"
            });

            model.Axes.Add(new LinearAxis
            {
                Position = AxisPosition.Bottom,
                Title    = "Frequency (Hz)",
            });

            var series = new FunctionSeries {
            };

            for (int i = 0; i < result.Length / 2; i++)
            {
                series.Points.Add(new DataPoint((double)i * sampleRate / result.Length, 20 * Math.Log10(result[i])));
            }

            model.Series.Add(series);
            view.Model = model;
        }
예제 #4
0
        private void FillDefaultPlotView(PlotView view, string yTitle, double[] result)
        {
            var model = new PlotModel {
            };

            model.Axes.Add(new LinearAxis
            {
                Title = yTitle
            });

            model.Axes.Add(new LinearAxis
            {
                Position = AxisPosition.Bottom,
                Title    = "Time (s)"
            });

            var series = new FunctionSeries {
            };

            for (int i = 0; i < result.Length; i++)
            {
                series.Points.Add(new DataPoint((double)i * length.TotalSeconds / result.Length, result[i]));
            }

            model.Series.Add(series);
            view.Model = model;
        }
예제 #5
0
        static void createSinGraph()
        {
            var    s    = new FunctionSeries((x) => Math.Sin(x), 0, 10, 0.1);
            var    plot = FastPlot.ShowFuncGraph(s, out _);
            double a    = 1;
            var    sw   = System.Diagnostics.Stopwatch.StartNew();

            while (!((Plot)plot).IsDisposed)
            {
                Thread.Sleep(200);

                for (int i = 0; i < s.Points.Count; i++)
                {
                    var p = s.Points[i];
                    s.Points[i] = new OxyPlot.DataPoint(p.X, Math.Sin(p.X + sw.ElapsedMilliseconds));
                }
                s.Points.Add(new OxyPlot.DataPoint(s.Points.Last().X + a, a));


                //plot.Refresh(s, 0);
                plot.Refresh();

                a += 0.1;
            }
        }
예제 #6
0
        //return a functionserie for derivative Newton
        public FunctionSeries GetFunctionSerieForDerivativeNewton()
        {
            FunctionSeries serie = new FunctionSeries();

            serie.Title = "Derivative Newton";
            double result;
            double h = 0.1;

            for (double x = -50; x < 50; x += 0.001)
            {
                try
                {
                    result = (RootFunc.Calculate(x + h) - RootFunc.Calculate(x)) / h;
                    if (Math.Abs(result) > 100)
                    {
                        serie.Points.Add(DataPoint.Undefined);
                    }
                    else
                    {
                        DataPoint data = new DataPoint(x, result);
                        serie.Points.Add(data);
                    }
                }
                catch (DivideByZeroException)
                {
                    serie.Points.Add(DataPoint.Undefined);
                }
            }
            return(serie);
        }
예제 #7
0
        //return the functionserie for the n-polinomial
        public FunctionSeries GetFunctionSerieForMatrix()
        {
            FunctionSeries serie = new FunctionSeries();

            serie.Title = (PointList.Count - 1) + "-polinomial";
            double[] coefficient = GetArrayOfCoefficient();
            double   result      = 0;

            try
            {
                for (double x = -50; x <= 50; x += 0.01)
                {
                    for (int i = 0; i < GetArrayOfCoefficient().Length; i++)
                    {
                        result += coefficient[i] * Math.Pow(x, i);
                    }
                    DataPoint data = new DataPoint(x, (double)result);
                    serie.Points.Add(data);
                    result = 0;
                }
            }
            catch (DivideByZeroException)
            {
                serie.Points.Add(DataPoint.Undefined);
            }
            return(serie);
        }
예제 #8
0
        public FunctionSeries GetFunctionSerieForDerivativeAnalyticallySimplify()
        {
            FunctionSeries serie = new FunctionSeries();

            serie.Title = "Derivative simplified";
            double result;

            for (double x = -50; x < 50; x += 0.001)
            {
                try
                {
                    result = RootFunc.GetDerivativeAnalytically().SimplifyFunction().Calculate(x);
                    if (Math.Abs(result) > 100)
                    {
                        serie.Points.Add(DataPoint.Undefined);
                    }
                    else
                    {
                        DataPoint data = new DataPoint(x, (double)result);
                        serie.Points.Add(data);
                    }
                }
                catch (DivideByZeroException)
                {
                    serie.Points.Add(DataPoint.Undefined);
                }
            }
            return(serie);
        }
예제 #9
0
        //return a serie of points for main function
        public FunctionSeries GetFunctionSerieMainFunction()
        {
            FunctionSeries serie = new FunctionSeries();

            serie.Title = "Main Funtion";
            double result = 0;

            for (double x = -50; x < 50; x += 0.01)
            {
                try
                {
                    result = RootFunc.Calculate(x);
                    if (Math.Abs(result) > 100)
                    {
                        serie.Points.Add(DataPoint.Undefined);
                    }
                    else
                    {
                        DataPoint data = new DataPoint(x, result);
                        serie.Points.Add(data);
                    }
                }
                catch (DivideByZeroException)
                {
                    serie.Points.Add(DataPoint.Undefined);
                }
            }
            return(serie);
        }
예제 #10
0
        public static FunctionSeries DrawFunction(Polynomial polynomial, string title, double discretizationValue)
        {
            Func <double, double> fx = (x) => polynomial.ValueX10 * Math.Pow(x, 10) +
                                       polynomial.ValueX9 * Math.Pow(x, 9) + polynomial.ValueX8 * Math.Pow(x, 8) +
                                       polynomial.ValueX7 * Math.Pow(x, 7)
                                       + polynomial.ValueX6 * Math.Pow(x, 6) +
                                       polynomial.ValueX5 * Math.Pow(x, 5) + polynomial.ValueX4 * Math.Pow(x, 4)
                                       + polynomial.ValueX3 * Math.Pow(x, 3) +
                                       polynomial.ValueX2 * Math.Pow(x, 2) + polynomial.ValueX * x +
                                       polynomial.FreeValue;

            if (discretizationValue < 10)
            {
                discretizationValue = 10;
            }

            var functionSeries = new FunctionSeries(fx, -100, 100, 1 / discretizationValue, title)
            {
                MarkerSize = 2,
                MarkerType = MarkerType.Diamond
            };


            return(functionSeries);
        }
예제 #11
0
파일: Form1.cs 프로젝트: Azmalent/itmo3
        private void drawPlot(UnaryFunc func, UnaryFunc approx, double x0, double xn)
        {
            //Отступ, чтобы отрезок интерполяции занимал 75% графика (отступы - 12.5% каждый)
            double offset = (xn - x0) * 0.125;
            double left   = x0 - offset;
            double right  = xn + offset;

            if (left > right)
            {
                double temp = left;
                left  = right;
                right = temp;
            }

            var colors = new List <OxyColor> {
                OxyColors.RoyalBlue, OxyColors.Red
            };
            var myModel = new PlotModel
            {
                DefaultColors       = colors,
                LegendItemAlignment = OxyPlot.HorizontalAlignment.Center,
                LegendPosition      = LegendPosition.BottomCenter,
                LegendOrientation   = LegendOrientation.Horizontal,
                LegendPlacement     = LegendPlacement.Outside,
            };

            var precisePlot = new FunctionSeries(func, left, right, 0.1, "Точное решение");
            var approxPlot  = new FunctionSeries(approx, left, right, 0.1, "Приближённое решение");

            myModel.Series.Add(precisePlot);
            myModel.Series.Add(approxPlot);

            plotView1.Model = myModel;
        }
        /// <summary>
        /// TODO: This method needs implementing before the deadline.
        /// </summary>
        /// <param name="date1"></param>
        /// <param name="date2"></param>
        /// <returns></returns>
        public static PieSeries GetTicketSoldAcrossADate(DateTime date1, DateTime date2)
        {
            List <Ticket> ticket = new List <Ticket>();

            using (var handler = new DataHandler())
            {
                ticket = handler.GetAllTickets();
            }

            var sortedTickets = ticket.Where(t =>
                                             t.Screening.DateAndTime.Date > date1.Date && t.Screening.DateAndTime.Date < date2).ToList();

            if (sortedTickets.Count == 0)
            {
                MessageBox.Show("there are no tickets for those dates");
                return(new PieSeries());
            }

            sortedTickets.OrderByDescending(t => t.Screening.DateAndTime.Date);

            FunctionSeries series = new FunctionSeries();

            List <DataPoint> points = new List <DataPoint>();

            foreach (var sortedTicket in sortedTickets)
            {
            }
            return(new PieSeries());
        }
예제 #13
0
        /// <summary>
        /// Создание многоугольника
        /// </summary>
        private void CreatePolygon()
        {
            polygon.AddVertex(new Point(6254502.76289210, 7959144.61893362)); // 6254502.76284217, 7959144.61893362
            polygon.AddVertex(new Point(6254354.66776772, 7958316.63171740)); // 6254354.66756772, 7958316.63171740
            polygon.AddVertex(new Point(6255391.33448884, 7957811.76146361)); // 6255391.33448884, 7957811.76146361
            polygon.AddVertex(new Point(6256148.63986953, 7958521.94542061)); // 6256148.63986953, 7958521.94562061
            polygon.AddVertex(new Point(6255677.42463366, 7959386.95665544)); // 6255677.42763266, 7959386.95665544
            polygon.AddVertex(new Point(6255027.82490611, 7959514.85211973)); // 6255027.82790611, 7959514.85711973

            for (int i = 0; i < polygon.CountVertices; i++)
            {
                // Если достигнута последняя вершина
                if (i == polygon.CountVertices - 1)
                {
                    // то соединяем с первой
                    polygon.AddEdge(new Segment(polygon.Vertices[i], polygon.Vertices[0]));
                }
                else
                {
                    polygon.AddEdge(new Segment(polygon.Vertices[i], polygon.Vertices[i + 1]));
                }
            }

            FunctionSeries lines = new FunctionSeries();

            for (int i = 0; i < polygon.CountVertices; i++)
            {
                lines.Points.Add(new DataPoint(polygon.Vertices[i].X, polygon.Vertices[i].Y));
            }
            lines.Points.Add(new DataPoint(polygon.Vertices[0].X, polygon.Vertices[0].Y));
            Graph.Model.Series.Add(lines);
        }
예제 #14
0
파일: Matrix.cs 프로젝트: Hainv201/CPP
        public FunctionSeries GetPolynomialSeries()
        {
            FunctionSeries functionSeries = new FunctionSeries();

            GetMatrix();
            double[] coefficients = CalculateCoefficients();
            double   threshold    = 1000;

            for (double x = -60; x <= 60; x += 0.01)
            {
                double y = 0;
                for (int i = 0; i < coefficients.Length; i++)
                {
                    y += coefficients[i] * Math.Pow(x, coefficients.Length - 1 - i);
                }
                if (Math.Abs(y) > threshold)
                {
                    functionSeries.Points.Add(DataPoint.Undefined);
                }
                else
                {
                    functionSeries.Points.Add(new DataPoint(x, y));
                }
            }
            return(functionSeries);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MultiPolynomialChart"/> class.
        /// </summary>
        /// <param name="stringOptions">List of options. The options should have a format of "Degree CoefficientA CoefficientB..." for each polynomial.</param>
        /// <param name="minX">Minimum value for the x-axis.</param>
        /// <param name="maxX">Maximum value for the x-axis.</param>
        /// <param name="minY">Minimum value for the y-axis.</param>
        /// <param name="maxY">Maximum value for the y-axis.</param>
        public MultiPolynomialChart(string[] stringOptions, int minX, int maxX, int minY, int maxY)
            : base(minX, maxX, minY, maxY)
        {
            Polynomials = new List <Polynomial>();

            if (ValidateOptions(stringOptions))
            {
                var coefficientsList = ParseOptions(stringOptions);

                var series = 0;
                foreach (var coefficients in coefficientsList)
                {
                    var polynomial = new Polynomial(coefficients);

                    var polynomialSeries = new FunctionSeries(polynomial, ChartAreas["Chart"])
                    {
                        BorderWidth = 2
                    };
                    if (series < SeriesColorHierarchy.Length)
                    {
                        polynomialSeries.Color = SeriesColorHierarchy[series];
                    }

                    Series.Add(polynomialSeries);
                    Polynomials.Add(polynomial);
                    series++;
                }
            }
        }
예제 #16
0
        private static PlotModel CreateSquareWave(int n = 25)
        {
            var plot = new PlotModel { Title = "Square wave (Gibbs phenomenon)" };

            Func<double, double> f = (x) =>
                {
                    double y = 0;
                    for (int i = 0; i < n; i++)
                    {
                        int j = i * 2 + 1;
                        y += Math.Sin(j * x) / j;
                    }
                    return y;
                };

            var fs = new FunctionSeries(f, -10, 10, 0.0001, "sin(x)+sin(3x)/3+sin(5x)/5+...+sin(" + (2 * n - 1) + ")/" + (2 * n - 1));

            plot.Series.Add(fs);
            plot.Subtitle = "n = " + fs.Points.Count;

            plot.Axes.Add(new LinearAxis
                {
                    Position = AxisPosition.Left,
                    Minimum = -4,
                    Maximum = 4
                });
            plot.Axes.Add(new LinearAxis
                {
                    Position = AxisPosition.Bottom
                });

            return plot;
        }
        private void invalidateSeparationFunction(object sender, TextChangedEventArgs e)
        {
            invalidateCurrentRunValues();

            if (lineFunctionSeries != null)
            {
                plotModel.Series.Remove(lineFunctionSeries);
            }

            lineFunctionSeries = null;

            IEnumerable <TextBox> separatingFunctionTextBoxes = separatingFunctionParametersGrid.Children.OfType <TextBox>();
            int    boxesOk = 0;
            double value;

            foreach (TextBox textBox in separatingFunctionTextBoxes)
            {
                if (double.TryParse(textBox.Text, out value))
                {
                    boxesOk++;
                }
            }

            if (boxesOk == 2)
            {
                checkSeparationFunctionValues();
            }
        }
예제 #18
0
        private FunctionSeries MacLaurinSeries(List <double> derivateSeriesCoefficient)
        {
            FunctionSeries series    = new FunctionSeries();
            double         threshold = 1000;

            for (double i = -60; i <= 60; i += 0.01)
            {
                double y = RootFunction.CalculateValue(0);
                for (int nr = 1; nr < derivateSeriesCoefficient.Count; nr++)
                {
                    double factorial = 1;
                    for (int j = 1; j <= nr; j++)
                    {
                        factorial *= j;
                    }
                    y += (derivateSeriesCoefficient.ElementAt(nr) * Math.Pow(i, nr)) / factorial;
                }
                if (Math.Abs(y) > threshold)
                {
                    series.Points.Add(DataPoint.Undefined);
                }
                else
                {
                    series.Points.Add(new DataPoint(i, y));
                }
            }
            return(series);
        }
예제 #19
0
        private static PlotView GetPlot(List <float> xAxisSamples, List <float> yAxisSamples)
        {
            var        plot  = new PlotView();
            LinearAxis XAxis = new LinearAxis()
            {
                Position = AxisPosition.Bottom
            };                                                                     //, Minimum = 0, Maximum = 10 };
            LinearAxis YAxis = new LinearAxis();

            PlotModel pm = new PlotModel();

            pm.Axes.Add(XAxis);
            pm.Axes.Add(YAxis);

            FunctionSeries fs = new FunctionSeries();

            for (int i = 0; i < xAxisSamples.Count; i++)
            {
                double x = i;
                fs.Points.Add(new DataPoint(xAxisSamples[i], yAxisSamples[i]));
            }

            pm.Series.Add(fs);
            plot.Model = pm;
            //plot.Anchor = AnchorStyles.Left|AnchorStyles.Right;
            //plot.Size = new System.Drawing.Size(100, 100);
            plot.Dock = DockStyle.Fill;
            return(plot);
        }
예제 #20
0
        private void trueDerivativeButton_Click(object sender, EventArgs e)
        {
            plotter.CreateDerivativeTree();
            Plotter.derivativeRoot = plotter.SimplifyTree(Plotter.derivativeRoot);
            plotter.GetGraphImage(graphPictureBox, Plotter.derivativeRoot);

            try {
                var boundaries = Boundaries(xValueTextbox.Text);

                Func <double, double> d       = (m) => plotter.ProcessTree(m, Plotter.derivativeRoot);
                Func <double, double> f       = (m) => plotter.ProcessTree(m, plotter.Root);
                FunctionSeries        dSeries = new FunctionSeries(d, boundaries[0], boundaries[1], 0.1d, "Derivative");
                FunctionSeries        fSeries = new FunctionSeries(f, boundaries[0], boundaries[1], 0.1d, "Function");

                myModel = new PlotModel()
                {
                    Title = "Plot (derivative)"
                };
                myModel.Series.Add(dSeries);
                myModel.Series.Add(fSeries);
                plot.Model = myModel;

                plotGraph_called = true;

                var x = Task.Run(() => GetInputImageFromWolfram(
                                     plotter.PrefixToInfix(inputTextbox.Text.Replace(" ", string.Empty)),
                                     derivativePictureBox,
                                     wolframDerivative));
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
예제 #21
0
        public override void GenerateData()
        {
            var sinModel = new PlotModel();

            sinModel.Series.Add(new FunctionSeries(Math.Sin, 0, 10, 10000, "sin(x)"));
            SinModel = sinModel;

            var lineModel      = new PlotModel();
            var functionSeries = new FunctionSeries(F, 0, 10, 40, "F(x)")
            {
                Color = OxyColor.FromRgb(0, 0, 255)
            };

            lineModel.Series.Add(functionSeries);
            LineModel = lineModel;

            var barModel  = new PlotModel();
            var barSeries = new BarSeries
            {
                ItemsSource = Enumerable.Range(0, 8)
                              .Select(CreateBarItem)
            };

            barModel.Series.Add(barSeries);
            BarModel = barModel;
        }
        private void Painter(Dictionary <decimal, decimal> dictionary)
        {
            if (dictionary.Count == 0)
            {
                return;
            }

            PlotView plotView = new PlotView();

            plotView.Dock = DockStyle.Fill;
            panel1.Controls.Add(plotView);

            LinearAxis XAxis = new LinearAxis()
            {
                Position           = AxisPosition.Bottom,
                MajorGridlineStyle = LineStyle.Solid,
                MinorGridlineStyle = LineStyle.None,
            };


            //plotView.Model.Series.Add(functionSeries);
            PlotModel plotModel = new PlotModel();

            plotView.Model = plotModel;
            plotModel.Axes.Add(XAxis);
            FunctionSeries functionSeries = new FunctionSeries();
            Series         series         = new LineSeries();

            foreach (var x in dictionary)
            {
                DataPoint dataPoint = new DataPoint(Convert.ToDouble(x.Key), Convert.ToDouble(x.Value));
                functionSeries.Points.Add(dataPoint);
            }
            plotView.Model.Series.Add(functionSeries);
        }
예제 #23
0
        private void plotGraph_Click(object sender, EventArgs e)
        {
            string input = inputTextbox.Text.Replace(" ", string.Empty).ToLower();

            try {
                input = Plotter.DeleteAllOccurencesOfCharFromString(input, 'n');
                input = Plotter.DeleteAllOccurencesOfCharFromString(input, 'r');

                plotter.ProcessString(input);

                var boundaries = Boundaries(xValueTextbox.Text);

                Func <double, double> func = (m) => plotter.ProcessTree(m, plotter.Root);
                FunctionSeries        f    = new FunctionSeries(func, boundaries[0], boundaries[1], 0.1d, "Your Function");

                myModel = new PlotModel()
                {
                    Title = "Plot"
                };
                myModel.Series.Add(f);
                plot.Model = myModel;

                plotter.GetGraphImage(graphPictureBox, plotter.Root);

                plotGraph_called = true;

                var x = Task.Run(() => GetInputImageFromWolfram(plotter.PrefixToInfix(input), functionPictureBox));
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
예제 #24
0
        private void Euler_CheckedChanged(object sender, EventArgs e)
        {
            pv.Model = new PlotModel {
                Title = "f(x,y)=tan(x+2y)/(x^2-y)  y(1)=1 Euler"
            };
            dv.Rows.Clear();
            FunctionSeries fs = new FunctionSeries();

            pv.Model.Series.Add(fs);
            fs.Color        = OxyColors.Black;
            fs.MarkerStroke = OxyColors.Red;
            fs.MarkerType   = MarkerType.Cross;
            fs.MarkerSize   = 5;

            x = new double[n];
            y = new double[n];

            // x[0] = 0;
            // y[0] = 1;
            x[0] = 1;
            y[0] = 1;
            fs.Points.Add(new DataPoint(x[0], y[0]));

            double yii;

            for (int i = 0; i < n - 1; i++)
            {
                yii      = y[i] + h * func(x[i], y[i]);
                y[i + 1] = y[i] + h / 2 * (func(x[i], y[i]) + func(x[i] + h, yii));
                x[i + 1] = x[i] + h;
                fs.Points.Add(new DataPoint(x[i + 1], y[i + 1]));
            }

            ShowPoints();
        }
예제 #25
0
        public static void DrawSimpleMethodFunction(List <double> roots)
        {
            var lineSeries = new LineSeries();

            lineSeries.Color = OxyColor.FromRgb(0, 0, 150);

            for (int i = 1; i < roots.Count; ++i)
            {
                lineSeries.Points.Add(new DataPoint(roots[i - 1], roots[i]));

                var rootLine = new LineSeries();
                rootLine.LineStyle       = LineStyle.Dash;
                rootLine.StrokeThickness = 1;
                rootLine.Color           = OxyColor.FromRgb(0, 0, 0);

                rootLine.Points.Add(new DataPoint(roots[i - 1], roots[i]));
                rootLine.Points.Add(new DataPoint(roots[i - 1], 0));

                PlotUnit1Model.Series.Add(rootLine);
            }
            PlotUnit1Model.Series.Add(lineSeries);

            var funcSeries = new FunctionSeries(x => x, 0, roots.First(), 0.5, "y = x");

            funcSeries.Color     = OxyColor.FromArgb(80, 0, 100, 100);
            funcSeries.LineStyle = LineStyle.Dot;
            PlotUnit1Model.Series.Add(funcSeries);
        }
예제 #26
0
        private void Adams_CheckedChanged(object sender, EventArgs e)
        {
            pv.Model = new PlotModel {
                Title = "f(x,y)=tan(x+2y)/(x^2-y)  y(1)=1 Adams"
            };
            dv.Rows.Clear();
            FunctionSeries fs = new FunctionSeries();

            pv.Model.Series.Add(fs);
            fs.Color        = OxyColors.Black;
            fs.MarkerStroke = OxyColors.Red;
            fs.MarkerType   = MarkerType.Cross;
            fs.MarkerSize   = 5;

            x = new double[n];
            y = new double[n];
            f = new double[n];

            //x[0] = 0;

            //y[0] = 1;
            x[0] = 1;
            y[0] = 1;
            f[0] = func(x[0], y[0]);

            fs.Points.Add(new DataPoint(x[0], y[0]));


            //Calculating the approximate value in the 1st point by Euler's method.
            x[1] = x[0] + h;
            y[1] = y[0] + h * f[0];
            f[1] = func(x[1], y[1]);

            fs.Points.Add(new DataPoint(x[1], y[1]));

            //Calculating the approximate value in the 2nd point by 2nd order Adams method.
            x[2] = x[1] + h;
            y[2] = y[1] + h * (3 / 2 * f[1] - 1 / 2 * f[0]);
            f[2] = func(x[2], y[2]);
            fs.Points.Add(new DataPoint(x[2], y[2]));


            //Calculating the approximate value in the 3rd point by 3rd order Adams method.
            x[3] = x[2] + h;
            y[3] = y[2] + h / 12 * (23 * f[2] - 16 * f[1] + 5 * f[0]);
            f[3] = func(x[3], y[3]);

            fs.Points.Add(new DataPoint(x[3], y[3]));

            //Calculating approximate values in subsequent points by 4th order Adams method.
            for (int i = 3; i < n - 1; i++)
            {
                y[i + 1] = y[i] + h / 24 * (55 * f[i] - 59 * f[i - 1] + 37 * f[i - 2] - 9 * f[i - 3]);
                x[i + 1] = x[i] + h;
                f[i + 1] = func(x[i + 1], y[i + 1]);
                fs.Points.Add(new DataPoint(x[i + 1], y[i + 1]));
            }
            ShowPoints();
        }
예제 #27
0
파일: Form1.cs 프로젝트: fbakly/Micro2Final
        private void SetLatestReading(FunctionSeries fs)
        {
            var LastElement  = fs.Points.ElementAt(fs.Points.Count - 1);
            var LastDateTime = DateTimeAxis.ToDateTime(LastElement.X);
            var LastLux      = LastElement.Y;

            label2.Text = (LastLux + " Lux at " + LastDateTime.ToString("HH:mm dd/MM/yyyy"));
        }
예제 #28
0
 public void addCurve(FunctionSeries f)
 {
     if (curve != null)
     {
         DataPlot.Series.RemoveAt(2);
     }
     curve = f;
     DataPlot.Series.Add(curve);
 }
예제 #29
0
        public Visualization AddConstraints(IList <Constraint> constraints, Func <int, OxyPalette> paletteInitializer = null, OxyColor color = default(OxyColor), double xMin = -100, double xMax = 100, double step = 0.5)
        {
            var plot = Plots.Last();

            OxyPalette palette = null;

            if (paletteInitializer != null)
            {
                palette = paletteInitializer.Invoke(constraints.Count == 1 ? constraints.Count + 1 : constraints.Count);
            }
            else
            {
                color = color == default(OxyColor) ? OxyColors.Black : color;
            }

            for (var i = 0; i < constraints.Count; i++)
            {
                Series series;

                if (constraints[i] is QuadraticConstraint)
                {
                    var a = constraints[i].Terms[2].Coefficient * -0.5;
                    var b = constraints[i].Terms[3].Coefficient * -0.5;
                    var r = Math.Sqrt(constraints[i].LimitingValue + (a * a) + (b * b));

                    series = new FunctionSeries(t => a + r * Math.Cos(t), t => b + r * Math.Sin(t), 0, 2 * Math.PI, 1000)
                    {
                        Color = palette?.Colors[i] ?? color
                    };
                }
                else
                {
                    var denominator = constraints[i].Terms[1].Coefficient;
                    var aNominator  = constraints[i].Terms[0].Coefficient;
                    var bNominator  = constraints[i].LimitingValue;

                    if (denominator == 0)
                    {
                        denominator = 1;
                        aNominator *= 10000;
                        bNominator *= 10000;
                    }

                    var a = aNominator / denominator;
                    var b = bNominator / denominator;

                    series = new FunctionSeries(x => b - a * x, xMin, xMax, step)
                    {
                        Color = palette?.Colors[i] ?? color,
                    };
                }

                plot.Model.Series.Add(series);
            }

            return(this);
        }
예제 #30
0
        public void Update()
        {
            this.curve = (x) => Amp *Math.Cos((2 * Math.PI *Freq) *x);

            FunctionSeries funcVals = new FunctionSeries(curve, 0, 0.1, 0.001);

            funcVals.TrackerFormatString = Model.Title;
            Model.Series[0] = funcVals;
        }
예제 #31
0
        private void calculateMcLaurinSeriesButton_Click(object sender, EventArgs e)
        {
            int order = int.Parse(mcLaurienOrderTextBox.Text); // get the order for the maclaurien

            if (!(order >= 1 && order <= 8))                   // check for the right input
            {
                MessageBox.Show("Please input a number that is bigger than 1 and less than 8!");
                return;
            }

            // CHANGE IT BACK HERE TO 'OUT' INSTEAD OF 'REF'
            BaseNode mcLaurienRoot;

            plotter.CreateMcLaurienSeries(out mcLaurienRoot, order);  // output mclaurien series

            mcLaurienRoot = plotter.SimplifyTree(mcLaurienRoot);
            plotter.GetGraphImage(graphPictureBox, mcLaurienRoot);

            List <DataPoint> mcLaurienPoints = new List <DataPoint> ();
            FunctionSeries   mcLaurienSeries = new FunctionSeries {
                Title = "McLaurien"
            };
            List <DataPoint> graphPoints = new List <DataPoint> ();
            FunctionSeries   graphSeries = new FunctionSeries {
                Title = "Graph"
            };

            try {
                var boundaries = Boundaries(xValueTextbox.Text);

                var realBoundaries = GetNewRangeBasedUponOldOne(plotter.Root, mcLaurienRoot, boundaries[0], boundaries[1]);

                for (double i = realBoundaries.lower; i < realBoundaries.upper; i += 0.3)
                {
                    mcLaurienPoints.Add(new DataPoint(i, plotter.ProcessTree(i, mcLaurienRoot)));
                }

                for (int i = boundaries[0]; i < boundaries[1]; i++)
                {
                    graphPoints.Add(new DataPoint(i, plotter.ProcessTree(i, plotter.Root)));
                }

                mcLaurienSeries.Points.AddRange(mcLaurienPoints);
                graphSeries.Points.AddRange(graphPoints);
                myModel = new PlotModel()
                {
                    Title = "McLaurien Series (order = " + order + ")"
                };
                myModel.Series.Add(mcLaurienSeries);
                myModel.Series.Add(graphSeries);
                plot.Model = myModel;

                plotGraph_called = true;
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
 protected override PlotModel createModel(List<DataPoint> points)
 {
     var plotModel = new PlotModel();
     var functionSeries = new FunctionSeries();
     functionSeries.Points.AddRange(points);
     plotModel.Series.Add(functionSeries);
     plotModel.Title = Title;
     Points = functionSeries.Points;
     return plotModel;
 }
예제 #33
0
        public void printRegression(double a, double b, Boolean isTemp = false, int iterationNumber = 0)
        {
            if (lastTempSeries != null)
            {
                GraphModel.Series.Remove(lastTempSeries);
            }
            Series series = new FunctionSeries(delegate(double startAge) { return a * startAge + b; }, 4, 15, 2);
            series.Title = isTemp ? "mezivýsledek " + iterationNumber.ToString() : "Regrese";
            if (isTemp)
            {
                lastTempSeries = series;
            }

            this.GraphModel.Series.Add(series);
        }
예제 #34
0
        public static PlotModel AnnotationLayers()
        {
            var model = new PlotModel { Title = "AnnotationLayers" };

            var a1 = new RectangleAnnotation { MinimumX = 10, MaximumX = 20, MinimumY = -1, MaximumY = 1, Layer = AnnotationLayer.BelowAxes };
            var a2 = new RectangleAnnotation { MinimumX = 30, MaximumX = 40, MinimumY = -1, MaximumY = 1, Layer = AnnotationLayer.BelowSeries };
            var a3 = new RectangleAnnotation { MinimumX = 50, MaximumX = 60, MinimumY = -1, MaximumY = 1, Layer = AnnotationLayer.AboveSeries };
            model.Annotations.Add(a1);
            model.Annotations.Add(a2);
            model.Annotations.Add(a3);
            var s1 = new FunctionSeries(Math.Sin, 0, 100, 0.01);
            model.Series.Add(s1);
            a1.MouseDown += (s, e) =>
            {
                model.Subtitle = "Clicked annotation below axes";
                model.InvalidatePlot(true);
                e.Handled = true;
            };
            a2.MouseDown += (s, e) =>
            {
                model.Subtitle = "Clicked annotation below series";
                model.InvalidatePlot(true);
                e.Handled = true;
            };
            a3.MouseDown += (s, e) =>
            {
                model.Subtitle = "Clicked annotation above series";
                model.InvalidatePlot(true);
                e.Handled = true;
            };
            s1.MouseDown += (s, e) =>
            {
                model.Subtitle = "Clicked series";
                model.InvalidatePlot(true);
                e.Handled = true;
            };

            return model;
        }
        public ViewSettingsViewModel()
        {
            var viewSettings = ((App)Application.Current).ViewSettings;
            this.SelectedPlotStyle = viewSettings.ToReactivePropertyAsSynchronized(self => self.PlotStyle).AddTo(this.disposables);

            this.SamplePlotModel = new OxyPlot.PlotModel()
            {
                Axes =
                {
                    new OxyPlot.Axes.LinearAxis() { Unit = "A", Position = OxyPlot.Axes.AxisPosition.Left, Minimum = 0 },
                    new OxyPlot.Axes.DateTimeAxis() { Unit = "Time", Position = OxyPlot.Axes.AxisPosition.Bottom },
                },
            };
            var sampleSeries = new FunctionSeries(x => Math.Sin(x*Math.PI*2), 0, 1, 1000, "Total Current");
            this.SamplePlotModel.Series.Add(sampleSeries);

            this.SelectedPlotStyle
                .Do(style =>
                {
                    var foregroundColor = style.PlotForeground.ToOxyColor();
                    this.SamplePlotModel.Background = style.PlotBackground.ToOxyColor();
                    this.SamplePlotModel.TextColor = foregroundColor;
                    this.SamplePlotModel.PlotAreaBorderColor = foregroundColor;
                    foreach (var axis in this.SamplePlotModel.Axes)
                    {
                        axis.MajorGridlineColor = foregroundColor;
                        axis.MinorGridlineColor = foregroundColor;
                        axis.TextColor = foregroundColor;
                        axis.AxislineColor = foregroundColor;
                        axis.TicklineColor = foregroundColor;
                    }
                    sampleSeries.Color = style.SeriesColor.ToOxyColor();
                    this.SamplePlotModel.InvalidatePlot(false);
                })
                .OnErrorRetry()
                .Subscribe()
                .AddTo(this.disposables);
        }
예제 #36
0
 private IEnumerable<DataPoint> GetSampledSinus()
 {
     var series = new FunctionSeries(Math.Sin, 0, 4*Math.PI, 100);
     return series.Points;
 }
예제 #37
0
		public async void InitPlot( )
		{
			var reader = new CsvGridReader( 1024, ';' );

			OpenFileDialog openFileDialog = new OpenFileDialog
			{
				Filter = "Text files|*.csv",
				ValidateNames = true
			};

			var column = 0;

			var fileName = openFileDialog.ShowDialog( ) == true ? openFileDialog.FileName : null;

			if ( fileName == null )
			{ return; }

			var grid = await Task<IGrid>.Factory.StartNew( ( ) => reader.Read( fileName, false, false ) );

			double left = double.MaxValue, right = double.MinValue;

			for ( int i = 0; i < grid.RowCount; ++i )
			{
				var value = grid.GetValue( i, column );
				left = left < value ? left : value;
				right = right > value ? right : value;
			}

			var quantizer = new Quantizer( left, right );

			var empirical = new EmpiricalDistribution( grid, column );

			var q = await Task<IQuantization>.Factory.StartNew( ( ) => quantizer.Quantize( 15, 1e-3, empirical ) );

			var zero = new LineSeries
			{
				Color = OxyColor.FromRgb( 0, 0, 0 ),
				StrokeThickness = 1
			};
			zero.Points.Add( new DataPoint( left, 0 ) );
			zero.Points.Add( new DataPoint( right, 0 ) );
			plot.Series.Add( zero );

			var func = new FunctionSeries( x => empirical.Density( x ), left, right, 1e-2 );
			plot.Series.Add( func );

			foreach ( var border in q.Borders )
			{
				var line = new LineSeries
				{
					LineStyle = LineStyle.Dash,
					Color = OxyColor.FromRgb( 0, 0, 0 ),
					StrokeThickness = 1
				};
				line.Points.Add( new DataPoint( border, 3e-1 ) );
				line.Points.Add( new DataPoint( border, -3e-2 ) );
				plot.Series.Add( line );
			}

			foreach ( var code in q.Codes )
			{
				var line = new LineSeries
				{
					LineStyle = LineStyle.Dash,
					Color = OxyColor.FromRgb( 140, 140, 140 ),
					StrokeThickness = 0.5
				};
				line.Points.Add( new DataPoint( code, 3e-1 ) );
				line.Points.Add( new DataPoint( code, -3e-2 ) );
				plot.Series.Add( line );
			}

			var codes = from code in q.Codes
			            select new ScatterPoint( code, empirical.Density( code ) );

			var points = new ScatterSeries
			{
				MarkerType = MarkerType.Circle,
				MarkerStroke = OxyColor.FromRgb( 2, 133, 230 )/*( 255, 0, 0 )*/,
				MarkerFill = OxyColor.FromRgb( 2, 133, 230 )/*( 255, 115, 41 )*/
			};
			points.Points.AddRange( codes );

			plot.Series.Add( points );

			PlotView.Model = plot;
		}