Beispiel #1
0
        private void DrawWithEulerMethod(BaseChart chart, Series series, double x, double y, double[] parameters)
        {
            for (int i = 0; i < _iterations; i += IterationsStep)
            {
                series.Points.AddXY(x, y);

                /*Если попытаться написать x += _stepValue * chart.f(x, y); y += _stepValue * chart.g(x, y);
                 * То теряются какие то знаки после запятой, почему?
                 * */
                double nextX = x + _stepValue * chart.f(x, y);
                double nextY = y + _stepValue * chart.g(x, y);

                x = nextX;
                y = nextY;
            }
        }
Beispiel #2
0
        private void Draw_Button_Click(object sender, EventArgs e)
        {
            if (AreFieldsEmpty())
            {
                return;
            }

            string choosedChart  = ChooseChart_ComboBox.SelectedItem.ToString();
            string choosedMethod = ChooseMethod_ComboBox.SelectedItem.ToString();

            var startX     = 1.0;
            var startY     = 0.0;
            var stepValue  = 0.0;
            var iterations = 0;

            if (StartX_TextBox.Text.Length != 0 && StartY_TextBox.Text.Length != 0)
            {
                if (!double.TryParse(StartX_TextBox.Text, out startX) || !double.TryParse(StartY_TextBox.Text, out startY))
                {
                    MessageBox.Show("Недопустимые координаты.");
                    return;
                }
            }

            if (StepValue_TextBox.Text.Length != 0 && !double.TryParse(StepValue_TextBox.Text, out stepValue))
            {
                MessageBox.Show("Недопустимое значение шага.");
                return;
            }

            if (Iterations_TextBox.Text.Length != 0 && !int.TryParse(Iterations_TextBox.Text, out iterations) ||
                iterations < 0)
            {
                MessageBox.Show("Недопустимое количество итераций.");
                return;
            }

            BaseChart chartType = GetChartType();

            double[] parameters = GetParameters();
            string   methodName = ChooseMethod_ComboBox.SelectedItem.ToString();

            _manager.Draw(chartType, methodName, startX, startY, stepValue, iterations, parameters);
        }
Beispiel #3
0
        public void Draw(BaseChart chart, string method, double startX, double startY,
                         double stepValue, int iterations, double[] parameters)
        {
            _stepValue  = stepValue == 0 ? Default_stepValue : stepValue;
            _iterations = iterations == 0 ? DefaultIterations : iterations;

            string fullName = GetFullName(chart.BaseName, startX, startY, parameters);

            if (_chart.Series.FindByName(fullName) == null)
            {
                SetupSeries(fullName);
            }

            if (method.Equals("Метод Эйлера"))
            {
                DrawWithEulerMethod(chart, _chart.Series[fullName], startX, startY, parameters);
            }
            else if (method.Equals("Метод Рунге-Кутта"))
            {
                DrawWithRungeKutt(chart, _chart.Series[fullName], startX, startY, parameters);
            }
        }
Beispiel #4
0
        private void DrawWithRungeKutt(BaseChart chart, Series series, double x, double y, double[] parameters)
        {
            for (int i = 0; i < _iterations; i += IterationsStep)
            {
                double k1 = _stepValue * chart.f(x, y, parameters);
                double l1 = _stepValue * chart.g(x, y, parameters);

                double k2 = _stepValue * chart.f(x + k1 / 2, y + l1 / 2, parameters);
                double l2 = _stepValue * chart.g(x + k1 / 2, y + l1 / 2, parameters);

                double k3 = _stepValue * chart.f(x + k2 / 2, y + l2 / 2, parameters);
                double l3 = _stepValue * chart.g(x + k2 / 2, y + l2 / 2, parameters);

                double k4 = _stepValue * chart.f(x + k3, y + l3, parameters);
                double l4 = _stepValue * chart.g(x + k3, y + l3, parameters);

                series.Points.AddXY(x, y);

                x += RungeKuttConst * Math.Round(k1 + 2 * k2 + 2 * k3 + k4, 5);
                y += RungeKuttConst * Math.Round(l1 + 2 * l2 + 2 * l3 + l4, 5);
            }
        }