subroutine euler ( dydt, tspan, y0, n, m, t, y ) c*********************************************************************72 c cc euler() approximates the solution to an ODE using Euler's method. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 30 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. c c double precision tspan(2): contains the initial and final times. c c double precision y0(m): a column vector containing 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 double precision dy(m) external dydt integer i double precision t(n+1) double precision tfirst double precision tlast double precision tspan(2) double precision y(n+1,m) double precision y0(m) tfirst = tspan(1) tlast = tspan(2) dt = ( tlast - tfirst ) / real ( n ) t(1) = tspan(1) y(1,1:m) = y0(1:m) do i = 1, n t(i+1) = t(i) + dt call dydt ( t(i), y(i,1:m), dy ) y(i+1,1:m) = y(i,1:m) + dt * dy(1:m) end do return end