Example #1
0
        private List<Point> ChebyshevInterpolation(Function func)
        {
            List<Point> interpolated;
            int numberOfNodes;
            float a, b, jump;
            if (float.TryParse(tbJump.Text, out jump) &&
                float.TryParse(tbBegin.Text, out a) &&
                float.TryParse(tbEnd.Text, out b) &&
                int.TryParse(tbNodesNumber.Text, out numberOfNodes))
            {
                NewtonChebyshevInterpolation interpolator = new NewtonChebyshevInterpolation();
                List<Point> nodes = new List<Point>();
                List<double> domain = new List<double>();

                nodes = ChebyshevNodes(numberOfNodes, a, b, func.GetValue);

                for (double x = nodes[0].x; x < b; x += jump)
                {
                    domain.Add(x);
                }

                interpolated = interpolator.Interpolate(nodes, domain);

                FormPlot form = new FormPlot(nodes, interpolated, func.GetValue);
                form.Show();
            }
            else
            {
                MessageBox.Show("Wrong arguments. Note that a floating point number separator is coma (ex. 1,5).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }

            return interpolated;
        }
Example #2
0
        private List<Point> EquidistantInterpolation(Function func)
        {
            float jump;
            //float nodesJump;
            int numberOfNodes;
            //float startingNodeX;
            float a, b;
            List<Point> nodes = new List<Point>();
            List<Point> interpolated = new List<Point>();

            if (float.TryParse(tbJump.Text, out jump) &&
                //float.TryParse(tbJumpNodes.Text, out nodesJump) &&
                int.TryParse(tbNodesNumber.Text, out numberOfNodes) &&
                float.TryParse(tbBegin.Text, out a) &&
                float.TryParse(tbEnd.Text, out b))
            {
                NewtonInterpolation interpolator = new NewtonInterpolation();

                nodes = GenerateNodes(numberOfNodes, (float)(Math.Abs(a) + Math.Abs(b)) / (float)numberOfNodes, a, func.GetValue);

                Debug.Log("Interpolation started");
                DateTime time = DateTime.Now;

                for (double x = nodes[0].x; x < nodes[nodes.Count()-1].x; x += jump)
                {
                    interpolated.Add(new Point(x, interpolator.Interpolate(nodes, x)));
                }

                Debug.Log("Interpolation finished in " + (DateTime.Now - time).TotalSeconds.ToString() + " s.");

                FormPlot form = new FormPlot(nodes, interpolated, func.GetValue);
                form.Show();
            }
            else
            {
                MessageBox.Show("Wrong arguments. Note that a floating point number separator is coma (ex. 1,5).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }

            return interpolated;
        }