I am looking to find the explicit and implicit codes for Euler's method. In my search I am across the following code, I am wondering if this code is explicit? if not how could I change it to make it so?
import math
# First Order ODE (y' = f(x, y)) Solver using Euler method
# xa: initial value of independent variable
# xb: final value of independent variable
# ya: initial value of dependent variable
# n : number of steps (higher the better)
# Returns value of y at xb.
def Euler(f, xa, xb, ya, n):
h = (xb - xa) / float(n)
x = xa
y = ya
for i in range(n):
y += h * f(x, y)
x += h
return y
print(Euler(lambda x, y: math.cos(x) + math.sin(y), 0, 1, 1, 1000))
This code implements the explicit Euler scheme.
In order to be implicit, there would be an instruction like
in the inner loop, where
solve(equation, variable)is a suitable function to solve an equation (see here).