function euler( F, tspan, y0, n ) #*****************************************************************************80 # ## euler() uses Euler's method to integrate a simple ODE. # # Discussion: # # The exact solution is: # # y(t)=(7.1+(3//10)*sin(t)*exp(3t)- # (1//10)*cos(t)*exp(3t))*exp(-3t) # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 09 March 2024 # # Author: # # John Burkardt # # Input: # # function F(t,y): # # real tspan[2]: # # real y0: # # integer n: # # Output: # # real t[n+1], y[n+1]: # dt = ( tspan[2] - tspan[1] ) / n t = zeros(n+1) y = zeros(n+1) t[1] = tspan[1] y[1] = y0 for i in 1 : n t[i + 1] = t[i] + dt y[i + 1] = y[i] + dt * F( t[i], y[i] ) end return t, y end