subroutine midpoint ( dydt, tspan, y0, n, m, t, y ) c*****************************************************************************80 c cc midpoint() uses the midpoint method + fsolve_be() to solve an ODE. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 10 November 2023 c c Author: c c John Burkardt c c Input: c c external dydt: a subroutine that evaluates the right c hand side of the ODE, of the form c subroutine dydt ( t, y, dy ) c c double precision tspan(2): the initial and final times. c c double precision y0(m): the initial condition. c c integer n: the number of steps to take. c c integer m: the number of variables. c c Output: c c double precision t(n+1), y(n+1,m): the times and solution values. c implicit none integer m integer n double precision dt external dydt double precision fm(m) integer i integer info double precision t(n+1) double precision theta double precision tm double precision to double precision tol double precision tspan(2) double precision y(n+1,m) double precision y0(m) double precision ym(m) double precision yo(m) dt = ( tspan(2) - tspan(1) ) / n theta = 0.5D+00 tol = 1.0D-05 t(1) = tspan(1) y(1,1:m) = y0(1:m) do i = 0, n if ( i == 0 ) then t(i+1) = tspan(1) y(i+1,1:m) = y0(1:m) else to = t(i) yo = y(i,1:m) tm = t(i) + theta * dt ym(1:m) = y(i,1:m) c c Call fsolve_be() to compute ym. c call fsolve_be ( dydt, m, to, yo, tm, ym, fm, tol, info ) if ( info /= 1 ) then write ( *, '(a)' ) '' write ( *, '(a)' ) 'midpoint(): Fatal error!' write ( *, '(a,i10)' ) ' info = ', info stop 1 end if t(i+1) = t(i) + dt y(i+1,1:m) = ( 1.0D+00 / theta ) * ym(1:m) & + ( 1.0D+00 - 1.0D+00 / theta ) * y(i,1:m) end if end do return end