lines 28-143 of file: example/python/numeric/ode_multi_step.py # {xrst_begin numeric_ode_multi_step} # {xrst_comment_ch #} # # # Multiple Ode Steps # ################## # # Syntax # ****** # *y_all* = ``ode_multi_step`` ( *one_step* , *f* , *t_all* , *y_init* ) # # Purpose # ******* # The routine can be used with ``ad_double`` to solve an initial # value ODE # # .. math:: # # y^{(1)} (t) = f( t , y ) # # one_step # ******** # This routine executes one step of an ODE approximation method with the # following syntax: # # | |tab| *y1* = *one_step* ( *f* , *t0* , *y0* , *t_step* ) # # The elements of *y0* and the scalars above can be # ``float`` or ``a_double`` . # # t0 # == # is the initial time value for the step. # # y0 # == # is the initial value of :math:`y(t)` for the step. # # t_step # ====== # is the is the size of the step (in time). # # y1 # == # is the approximation for the ODE solution at time *t0* + *t_step* . # # fun # *** # # fun.set_t_all_index(index) # ========================== # Often, we use interpolation with knots to define :math:`f(t, y)`. # It is one of the subtitle issues of AD that even though values are the # same, derivatives might not be the same; e.g., # piecewise linear interpolation. # We must break the integration of the ODE at each of the knot # so we can use a method that assumes :math:`f(t, y)` is smooth. # Also so that AD can be used to compute derivatives of our solutions. # The function ``set_t_all_index`` # informs *fun* that we are currently integrating the time interval # # | |tab| [ *t_all* [ *index* ] , *t_all* [ *index* +1] ] # # so that it know which smooth function to represent # even if :math:`t` is at a knot and it matters if it is the interval # to the left or right of the knot. # The function ``set_t_all_index`` is called at the start # of each integration interval and before any of the other # *fun* member functions. # # fun.f(t, y) # =========== # This call evaluates the function that defines the ODE # # .. math:: # # y^{(1)} (t) = f [ t , y(t) ] # # one_step # ======== # The routine *one_step* may put extra requirements on *fun* . # # t_all # ***** # This is a numpy vector of time values at which the solution is calculated. # The type of its elements can be ``float`` or ``ad_double`` . # It must be either monotone increasing or decreasing. # # y_init # ****** # This is the value of :math:`y(t)` at the initial time # *t_all* [ 0 ] as a numpy vector. # The type of its elements can be ``float`` or ``ad_double`` . # # y_all # ***** # This is the approximate solution for :math:`y(t)` at all of the # times specified by *t_all* as a numpy array. # The value *y_all* [ *i* , *j* ] is the value of the j-th # component of :math:`y(t)` at time *t_all* [ *i* ] . # # {xrst_toc_hidden # example/python/numeric/ode_multi_step_xam.py # } # Example # ******* # :ref:`numeric_ode_multi_step_xam.py-name` # # Source Code # *********** # {xrst_literal # # BEGIN_ODE_MULTI_STEP # # END_ODE_MULTI_STEP # } # # {xrst_end numeric_ode_multi_step}