private void goButton_Click(object sender, RoutedEventArgs e)
        {
            Parser.Parser.Variable variableI;
            Parser.Parser parser = new Parser.Parser();

            parser = new Parser.Parser();
            parser.InputString = functionTextBox.Text;
            variableI = parser.GetVariable("x");

            PointCollection p = new PointCollection();

            Random r = new Random();

            for (float i = 0; i <= 10; i += 0.5f)
            {
                points.pointX.Add(i);
                variableI.value = i;
                clearSignal.Add(variableI.value);

                //variableI.value = (i % 3 == 0) ? i * (float)r.NextDouble() : i;
                //noiseSignal.Add(variableI.value);
                points.pointY.Add(parser.Calculate());
                p.Add(new Point(parser.Calculate(), i));
            }

            chart.DataContext = p;
        }
Example #2
0
        public float StudyFunction(float x)
        {
            VariableI.value = x;
            VariableN.value = EraCount;

            return(parser.Calculate());
        }
        private void goButton_Click(object sender, RoutedEventArgs e)
        {
            Parser.Parser.Variable VariableI;
            Parser.Parser parser = new Parser.Parser();

            parser = new Parser.Parser();
            parser.InputString = FunctionBox.Text;
            VariableI = parser.GetVariable("x");

            PointCollection p = new PointCollection();

            for (float i = 0; i < 10; i += 0.5f)
            {
                VariableI.value = i;
                p.Add(new Point(parser.Calculate(), i));
            }

            chart.DataContext = p;
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            double res = 0;

            if (double.TryParse(Left.Text, out res) || double.TryParse(Step.Text, out res) || double.TryParse(Right.Text, out res))
            {
            }
            else
            {
                string   expression = Expression.Text;
                string[] methods    = { "L", "T", "M" };
                bool?[]  method     = { LeftIntegral.IsChecked, TrapIntegral.IsChecked, MidIntegral.IsChecked };
                int      nomer      = 0;
                for (int i = 0; i < 3; i++)
                {
                    if (method[i] == true)
                    {
                        nomer = i;
                        break;
                    }
                }
                var values = new Dictionary <string, string> {
                    { "Action", "CalculateIntegral" },
                    { "Func", expression },
                    { "Left", Left.Text },
                    { "Right", Right.Text },
                    { "Step", Step.Text },
                    { "Method", methods[nomer] }
                };


                var response = await Sender.Sender.Send(values);

                var responseString = await response.Content.ReadAsStringAsync();

                Regex           argument = new Regex(@"([^\&]*)=([^\&]*)&", RegexOptions.Compiled);
                MatchCollection matches  = argument.Matches(responseString);

                Dictionary <string, double> arguments = new Dictionary <string, double>();
                foreach (Match item in matches)
                {
                    arguments.Add(item.Groups[1].Value, double.Parse(item.Groups[2].Value));
                }

                Parser.Parser parser = new Parser.Parser(expression);

                Chart chart = this.FindName("MyWinformChart") as Chart;
                chart.Series["Series1"].Points.Clear();
                chart.Series["Series2"].Points.Clear();

                double left  = Convert.ToDouble(Left.Text);
                double right = Convert.ToDouble(Right.Text);
                double step  = Convert.ToDouble(Step.Text);

                for (double i = 0; i < arguments.Count / 2 - 1; i++)
                {
                    chart.Series["Series1"].Points.AddXY(arguments[$"X{i}"], arguments[$"Y{i}"]);
                }

                for (double x = left; x < right + step / 2; x += step)
                {
                    chart.Series["Series2"].Points.AddXY(x, parser.Calculate(x));
                }
                Result.Text = arguments["Value"].ToString();
            }
        }
Example #5
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            double tr = 0;

            if (double.TryParse(Left.Text, out tr) || double.TryParse(Eps.Text, out tr) || double.TryParse(Right.Text, out tr))
            {
            }
            else
            {
                string expression = Expression.Text;
                Chart  chart      = this.FindName("MyWinformChart") as Chart;
                chart.Series.Clear();
                chart.Series.Add(new Series("Series1"));

                chart.Series[0].BorderWidth = 5;

                chart.Series["Series1"].ChartArea = "Default";
                chart.Series["Series1"].ChartType = SeriesChartType.Spline;

                double        left   = Convert.ToDouble(Left.Text);
                double        right  = Convert.ToDouble(Right.Text);
                double        step   = (right - left) / 20;
                Parser.Parser parser = new Parser.Parser(expression);



                if (MainWindow.isConnected)
                {
                    var values = new Dictionary <string, string> {
                        { "Action", "CalculateSecond" },
                        { "Func", expression },
                        { "Left", Left.Text },
                        { "Right", Right.Text },
                        { "Eps", Eps.Text }
                    };


                    var response = await Sender.Sender.Send(values);

                    var responseString = await response.Content.ReadAsStringAsync();

                    Regex           argument = new Regex(@"([^\&]*)=([^\&]*)&", RegexOptions.Compiled);
                    MatchCollection matches  = argument.Matches(responseString);

                    Dictionary <string, double> arguments = new Dictionary <string, double>();
                    foreach (Match item in matches)
                    {
                        arguments.Add(item.Groups[1].Value, double.Parse(item.Groups[2].Value));
                    }

                    for (double i = 0; i < arguments.Count / 2 - 1; i += 2)
                    {
                        chart.Series.Add(new Series($"Series{2 + i}"));
                        chart.Series[$"Series{2 + i}"].ChartArea   = "Default";
                        chart.Series[$"Series{2 + i}"].ChartType   = SeriesChartType.Spline;
                        chart.Series[$"Series{2 + i}"].BorderWidth = 3;

                        chart.Series[$"Series{2 + i}"].Points.AddXY(arguments[$"X{i}"], arguments[$"Y{i}"]);
                        chart.Series[$"Series{2 + i}"].Points.AddXY(arguments[$"X{i + 1}"], arguments[$"Y{i + 1}"]);
                        Result.Text = arguments["Value"].ToString();
                    }
                }
                else
                {
                    FPtr     f   = new FPtr(parser.Calculate);
                    int      n   = 0;
                    double[] res = new double[1000];

                    double integralValue = 0;
                    integralValue = MidFind(res, ref n, f, left, right, Convert.ToDouble(Eps.Text));
                    Result.Text   = integralValue.ToString();
                }
                for (double x = left; x < right + step / 2; x += step)
                {
                    chart.Series["Series1"].Points.AddXY(x, parser.Calculate(x));
                }
            }
        }