I am building a for loop using Euler's method for differential equations. The for loop however is not incrementing and only displaying the values for i=0 and not i=1 or i=2.
I have tried manually assigning all arguments and reconstructed the for loop.
import math
def Euler(a,b,N,alpha):
h=(b-a)/N
t=a
w=alpha
for i in range (0,N):
w=w+h*(math.exp(t-w))
t=a+(i*h)
return t,w
Euler(0,1,2,1)
I expect the function to return results for i=1 and i=2
return
is inside thefor
loop. (did you meant to putprint
there instead?)return
exits the function immediately, so your loop only executes once.