I thought I'd try to code a Euler's method problem into a recursive function, but I'd like to improve the reusablity of it by being able to pass in any arrangement of the x and y values for the statement. For example, in my code the equation is x + y / 7
but I'd like to be able to pass in an arbitrary equation such as (x ^ 2 + y ) / 2
or something to that effect.
Can I do that with numpy or is there a handwritten way I can implement that will do this?
The only thing I can think of is getting the equation via a string and converting/rebuilding the equation in the function to generate the results.
y = -4
x = 0
step = 1
def eulersMethod(y, x, step):
y = y+step*(x+y/7.)
if y < 7:
tmp = eulersMethod(y, x+step, step)
if tmp < 7:
y = tmp
return y
print(eulersMethod(y, x, step))