示例#1
0
        //calculates the value of the solution in the given point
        public double Solve(double x)
        {
            if (!x.IsFinite())
            {
                throw new ArgumentOutOfRangeException("x", "the input point is not finited");
            }

            if (x == initialCondition.x)//if the searched point is the initial one returns directly it
            {
                return(initialCondition.y);
            }

            Vector2D solution = new Vector2D();
            Vector2D previousNode, nextNode;

            if (nodeSelector != null)
            {
                previousNode = nodeSelector(x);
                nextNode     = previousNode;
            }
            else
            {
                previousNode = initialCondition;
                nextNode     = previousNode;
            }
            if (x > initialCondition.x)
            {
                for (int i = 0; i < maxIterations; i++)
                {
                    if (x < nextNode.x)
                    {
                        double intermediateStep = discretizer.IntermediateStep(x, previousNode, nextNode);
                        solution = Iteration(previousNode, intermediateStep);
                        break;
                    }
                    else if (x == nextNode.x)
                    {
                        solution = nextNode;
                        break;
                    }
                    else
                    {
                        previousNode = nextNode;
                        nextNode     = Iteration(nextNode, discretizer.CalculateRightStep(nextNode));
                    }
                }
            }
            else
            {
                for (int i = 0; i < maxIterations; i++)
                {
                    if (x > nextNode.x)
                    {
                        double intermediateStep = discretizer.IntermediateStep(x, previousNode, nextNode);
                        solution = Iteration(previousNode, intermediateStep);
                        break;
                    }
                    else if (x == nextNode.x)
                    {
                        solution = nextNode;
                        break;
                    }
                    else
                    {
                        previousNode = nextNode;
                        nextNode     = Iteration(nextNode, discretizer.CalculateLeftStep(nextNode));
                    }
                }
            }
            return(solution.y);
        }