/// <summary>
        /// Solves a set of coupled, conservative second order ordinary differential equation initial value problems using the given settings.
        /// </summary>
        /// <param name="rhs">The right hand side function.</param>
        /// <param name="x0">The initial value of the independent variable.</param>
        /// <param name="y0">The initial values of the functions.</param>
        /// <param name="yPrime0">The intial values of the functions' derivatives.</param>
        /// <param name="x1">The final value of the independent variable.</param>
        /// <param name="settings">The settings to use when solving the problem.</param>
        /// <returns>The solution, including the final value of the functions and their derivatives.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="rhs"/>, <paramref name="y0"/>, <paramref name="yPrime0"/>,
        /// or <paramref name="settings"/> is <see langword="null"/>.</exception>
        /// <exception cref="DimensionMismatchException"><paramref name="y0"/> and <paramref name="yPrime0"/> do not have the same
        /// dimension.</exception>
        /// <exception cref="NonconvergenceException">The ODE could not be integrated to the required precision before exhausting
        /// the maximum allowed number of <paramref name="rhs"/>evaluations.</exception>
        /// <remarks>
        /// <para>For information on conservative ODEs, see <see cref="FunctionMath.IntegrateConservativeOde(Func{double, double, double}, double, double, double, double, OdeEvaluationSettings)"/>.</para>
        /// </remarks>
        public static MultiOdeResult IntegrateConservativeOde(Func <double, IList <double>, IList <double> > rhs, double x0, IList <double> y0, IList <double> yPrime0, double x1, MultiOdeEvaluationSettings settings)
        {
            if (rhs == null)
            {
                throw new ArgumentNullException(nameof(rhs));
            }
            if (y0 == null)
            {
                throw new ArgumentNullException(nameof(y0));
            }
            if (yPrime0 == null)
            {
                throw new ArgumentNullException(nameof(yPrime0));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            if (y0.Count != yPrime0.Count)
            {
                throw new DimensionMismatchException();
            }

            FunctionMath.SetOdeDefaults(settings);

            MultiStoermerEngine   engine   = new MultiStoermerEngine(rhs, x0, y0, yPrime0, settings);
            BulrischStoerStrategy strategy = new BulrischStoerStrategy(engine);

            strategy.IntegrateTo(x1);
            return(engine.GetResult());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Solves a set of coupled ordinary differential equation initial value problems.
        /// </summary>
        /// <param name="rhs">The right hand side function, which returns the value of the derivative given
        /// the values of the independent variable and the function.</param>
        /// <param name="x0">The initial value of the independent variable.</param>
        /// <param name="y0">The initial value of the function.</param>
        /// <param name="x1">The final value of the independent variable.</param>
        /// <param name="settings">The settings to use when solving the problem.</param>
        /// <returns>The solution, including the final value of the function and its derivative.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="rhs"/>, <paramref name="y0"/>, or <paramref name="settings"/>
        /// is <see langword="null"/>.</exception>
        /// <exception cref="NonconvergenceException">The ODE could not be integrated to the required precision before exhausting
        /// the maximum allowed number of <paramref name="rhs"/>evaluations.</exception>
        /// <remarks>
        /// <para>This method integrates a set of coupled ordinary differential equations. The dependent variable y is a vector
        /// with any number of components, and the right-hand-side is a vector-valued function that gives the derivative
        /// of each component. Each component's derivative may depend itself and any other components, as well as on the independent variable.
        /// The independent variable x still takes only a single real value.</para>
        /// </remarks>
        public static MultiOdeResult IntegrateOde(Func <double, IReadOnlyList <double>, IReadOnlyList <double> > rhs, double x0, IReadOnlyList <double> y0, double x1, MultiOdeSettings settings)
        {
            if (rhs == null)
            {
                throw new ArgumentNullException(nameof(rhs));
            }
            if (y0 == null)
            {
                throw new ArgumentNullException(nameof(y0));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            FunctionMath.SetOdeDefaults(settings);

            MultiBulrischStoerEngine engine   = new MultiBulrischStoerEngine(rhs, x0, y0, settings);
            BulrischStoerStrategy    strategy = new BulrischStoerStrategy(engine);

            strategy.IntegrateTo(x1);
            return(engine.GetResult());
        }