/// <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());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Solves a conservative second order ordinary differential equation initial value problem 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 value of the function variable.</param>
        /// <param name="yPrime0">The intial value of the function derivative.</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">The <paramref name="rhs"/> or <paramref name="settings"/> is 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>A conservative ODE is an ODE of the form</para>
        /// <img src="../images/ConservativeODE.png" />
        /// <para>where the right-hand-side depends only on x and y, not on the derivative y'. ODEs of this form are called conservative because
        /// they exhibit conserved quantities: combinations of y and y' that maintain the same value as the system evolves. Many forms of
        /// Newtonian equations of motion, for example, are conservative ODEs, with conserved quantities such as energy, momentum, and
        /// angular momentum. Our specialized conservative ODE integrator is not only more efficient for conservative ODEs, but does a
        /// better job of maintaining the conserved quantities.</para>
        /// </remarks>
        public static OdeResult IntegrateConservativeOde(Func <double, double, double> rhs, double x0, double y0, double yPrime0, double x1, OdeEvaluationSettings settings)
        {
            if (rhs == null)
            {
                throw new ArgumentNullException(nameof(rhs));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            SetOdeDefaults(settings);

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

            strategy.IntegrateTo(x1);
            return(engine.GetResult());
        }
Ejemplo n.º 3
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());
        }