Beispiel #1
0
        private void InitializeGrid()
        {
            var d = _equation.d;
            var a = _equation.a;
            var b = _equation.b;
            var c = _equation.c;

            var tau = _params.TimeLimit / _params.TimeStepCount;
            Func <double, double> p1 = (x) => _conditions.InitialCondition(x, 0);
            Func <double, double> p2 = (x) => _conditions.DerivativeCondition(x, 0);
            var firstDerivative      = Derivative.FindByFunction(p1, 1, _params.SpaceBoundLeft, _params.SpaceBoundRight, _params.SpaceStepCount);
            var secondDerivative     = Derivative.FindByFunction(p1, 2, _params.SpaceBoundLeft, _params.SpaceBoundRight, _params.SpaceStepCount);

            for (int i = 0; i <= _params.SpaceStepCount; i++)
            {
                var x = GetSpaceCoordinate(i);
                _grid[i, 0] = p1(x);

                switch (_params.InitialApproximation)
                {
                case InitialApproximationType.FirstDegree:
                    _grid[i, 1] = p1(x) + p2(x) * tau;
                    break;

                case InitialApproximationType.SecondDegree:
                    _grid[i, 1] = p1(x) + p2(x) * tau
                                  + tau * tau / 2 * (a * secondDerivative[i] + b * firstDerivative[i] + c * p1(x) + _equation.f(x, 0) - d * p2(x));
                    break;
                }
            }
        }