Esempio n. 1
0
        public double ChordIterativeMethodRun()
        {
            var    method = new ChordIterativeMethod(function1, a1, b1, eps);
            double root   = method.Calculate();

            Plots.DrawChordMethodFunction(method.Roots, b1, function1);
            return(root);
        }
Esempio n. 2
0
        private double NewtonIterativeMethodRun()
        {
            var    method = new NewtonIterativeMethod(function1, derivative, a1, b1, eps);
            double root   = method.Calculate();

            Plots.DrawNewtonMethodFunction(method.Roots, function1);
            return(root);
        }
Esempio n. 3
0
        private double SimpleIterativeMethodRun()
        {
            var    method = new SimpleIterativeMethod(function1, derivative, a1, b1, eps);
            double root   = method.Calculate();

            Plots.DrawSimpleMethodFunction(method.Roots);
            return(root);
        }
Esempio n. 4
0
        private void calculateButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                function1  = ExpressionParser.GetFunction(functionInput.Text);
                derivative = ExpressionParser.GetFunction(derivativeInput.Text);

                a1 = double.Parse(intervalInputA.Text);
                b1 = double.Parse(intervalInputB.Text);

                if (a1 >= b1)
                {
                    throw new ArgumentException($"Incorrect interval: [{a1}; {b1}]\nb must be greater then a");
                }

                eps = double.Parse(epsilonInput.Text);

                Plots.PlotUnit1Model.Series.Clear();
                Plots.DrawInterval(Plots.PlotUnit1Model, a1, b1);
                Plots.DrawFunction(Plots.PlotUnit1Model, function1, a1, b1);

                double root = 0;
                if (methodSelect.SelectedIndex == 0)
                {
                    root = SimpleIterativeMethodRun();
                }
                else if (methodSelect.SelectedIndex == 1)
                {
                    root = NewtonIterativeMethodRun();
                }
                else if (methodSelect.SelectedIndex == 2)
                {
                    root = ChordIterativeMethodRun();
                }

                Plots.PlotUnit1Model.InvalidatePlot(true);

                resultTextBox.Text = $"x = {root}";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }
Esempio n. 5
0
        private void interpolateButton2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string[] xValuesString = xValuesInput.Text.TrimEnd(';').Split(';');
                double[] xValues       = new double[xValuesString.Length];
                for (int i = 0; i < xValuesString.Length; ++i)
                {
                    xValues[i] = double.Parse(xValuesString[i]);
                }

                string[] yValuesString = yValuesInput.Text.TrimEnd(';').Split(';');
                double[] yValues       = new double[yValuesString.Length];
                for (int i = 0; i < yValuesString.Length; ++i)
                {
                    yValues[i] = double.Parse(yValuesString[i]);
                }

                if (xValues.Length == 0 || yValues.Length == 0)
                {
                    throw new ArgumentException("One of the value lists is empty");
                }

                if (xValues.Length != yValues.Length)
                {
                    throw new ArgumentException("Lists of values have different lengths");
                }

                if (methodSelect3.SelectedIndex == 0)
                {
                    interpolationMethod2 = new LagrangeInterpolationMethod(xValues, yValues);
                }
                else if (methodSelect3.SelectedIndex == 1)
                {
                    interpolationMethod2 = new NewtonInterpolationForwardUniformMethod(xValues, yValues);
                }
                else if (methodSelect3.SelectedIndex == 2)
                {
                    interpolationMethod2 = new NewtonInterpolationBackUniformMethod(xValues, yValues);
                }
                else if (methodSelect3.SelectedIndex == 3)
                {
                    interpolationMethod2 = new NewtonInterpolationForwardUnevenMethod(xValues, yValues);
                }
                else if (methodSelect3.SelectedIndex == 4)
                {
                    interpolationMethod2 = new NewtonInterpolationBackUnevenMethod(xValues, yValues);
                }

                Plots.PlotInterpol2Model.Series.Clear();

                Plots.DrawFunction(Plots.PlotInterpol2Model, interpolationMethod2.Polynom, xValues[0], xValues[xValues.Length - 1], "255,100,100,200", "Interpolation polynom");
                Plots.DrawPoints(Plots.PlotInterpol2Model, xValues, yValues);

                Plots.PlotInterpol2Model.InvalidatePlot(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }
Esempio n. 6
0
        private void interpolateButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                function2 = ExpressionParser.GetFunction(functionInput2.Text);
                int nNodes = (int)nodesSlider.Value;
                a2 = double.Parse(intervalInputA2.Text);
                b2 = double.Parse(intervalInputB2.Text);

                if (a2 >= b2)
                {
                    throw new ArgumentException($"Incorrect interval: [{a2}; {b2}]\nb must be greater then a");
                }

                if (methodSelect2.SelectedIndex == 1 || methodSelect2.SelectedIndex == 2)
                {
                    nodesSelectMode.SelectedIndex = 0;
                }

                double[] xValues = null;
                if (nodesSelectMode.SelectedIndex == 0)
                {
                    xValues = InterpolationNodesSelector.SelectUniform(a2, b2, nNodes);
                }
                else if (nodesSelectMode.SelectedIndex == 1)
                {
                    xValues = InterpolationNodesSelector.SelectChebyshev(a2, b2, nNodes);
                }

                double[] yValues = new double[nNodes];
                for (int i = 0; i < nNodes; ++i)
                {
                    yValues[i] = function2(xValues[i]);
                }

                IInterpolationMethod interpolationMethod = null;
                if (methodSelect2.SelectedIndex == 0)
                {
                    interpolationMethod = new LagrangeInterpolationMethod(xValues, yValues);
                }
                else if (methodSelect2.SelectedIndex == 1)
                {
                    interpolationMethod = new NewtonInterpolationForwardUniformMethod(xValues, yValues);
                }
                else if (methodSelect2.SelectedIndex == 2)
                {
                    interpolationMethod = new NewtonInterpolationBackUniformMethod(xValues, yValues);
                }
                else if (methodSelect2.SelectedIndex == 3)
                {
                    interpolationMethod = new NewtonInterpolationForwardUnevenMethod(xValues, yValues);
                }
                else if (methodSelect2.SelectedIndex == 4)
                {
                    interpolationMethod = new NewtonInterpolationBackUnevenMethod(xValues, yValues);
                }

                Plots.PlotUnit2Model.Series.Clear();

                Plots.DrawInterval(Plots.PlotUnit2Model, a2, b2);
                Plots.DrawFunction(Plots.PlotUnit2Model, function2, a2, b2, "255,100,200,100", $"y = {functionInput2.Text}");
                Plots.DrawFunction(Plots.PlotUnit2Model, interpolationMethod.Polynom, a2, b2, "255,100,100,200", "Interpolation polynom");
                Plots.DrawPoints(Plots.PlotUnit2Model, xValues, yValues);

                Plots.PlotUnit2Model.InvalidatePlot(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }