Beispiel #1
0
        private (PointPairList basisPoints, PointPairList correctFuncValue) constructBasisAndCorrectFuncValues(TestFunctionBase testFunction)
        {
            PointPairList basisPoints      = new PointPairList();
            PointPairList correctFuncValue = new PointPairList();

            Func <int, double> getStepFunc = null;

            if (stepFixedMode.Checked)
            {
                if (!double.TryParse(stepTb.Text, out double fixedStep))
                {
                    fixedStep   = 0.2;
                    stepTb.Text = fixedStep.ToString();
                }
                getStepFunc = new Func <int, double>((int _) => fixedStep);
            }
            else
            {
                getStepFunc = new Func <int, double>((int iter) => testFunction.GetStep(iter));
            }

            // generate basis points and basis points with middle points from func
            int    currIter    = 0;
            double correctXMax = testFunction.XMax + 0.0001;

            for (double x = testFunction.XMin; x < correctXMax; x += getStepFunc(currIter))
            {
                basisPoints.Add(new PointPair(x, testFunction.GetValue(x)));

                if (double.IsNaN(basisPoints.Last().Y) || double.IsInfinity(basisPoints.Last().Y))
                {
                    throw new ArgumentException($"XMin == {testFunction.XMin} correctXMax == {correctXMax}\n" +
                                                $"basisPoints.Last() == {basisPoints.Last()}\n" +
                                                $"double.IsNaN(basisPoints.Last().Y) == {double.IsNaN(basisPoints.Last().Y)}\n" +
                                                $"double.IsInfinity(basisPoints.Last().Y) == {double.IsInfinity(basisPoints.Last().Y)}", nameof(testFunction));
                }

                PointPair curPoint = basisPoints.Last();
                correctFuncValue.Add(curPoint);

                double nextX = x + getStepFunc(currIter + 1);
                if (nextX < correctXMax)
                {
                    // here we should put middle points
                    double delta = (nextX - x) / (pointsBetweenBasisNumber + 1);
                    for (int pbi = 1; pbi <= pointsBetweenBasisNumber; pbi++)                       // pbi means Point Between Bassis Iter
                    {
                        double xMiddle = curPoint.X + pbi * delta;
                        correctFuncValue.Add(new PointPair(xMiddle, testFunction.GetValue(xMiddle)));
                    }
                }
                currIter++;
            }

            return(basisPoints, correctFuncValue);
        }