Mar-26-2019, 11:00 AM
I am writing a program dealing with recursion, so far the info given is
n, n+1, n+2, n+3. I have to reach 1000.
I have done it by using the list method and the if else method.
The first method returns a completely empty output and the second one
returns the word 'none'.
I am not sure where the error is.
n, n+1, n+2, n+3. I have to reach 1000.
I have done it by using the list method and the if else method.
The first method returns a completely empty output and the second one
returns the word 'none'.
I am not sure where the error is.
#list method h=1/1000 a=-0.5 x=math.exp(h*a) y=math.exp(2*h*a) L=[1.0,x,y] for i in range(0,1000): L.append(L[-1] + h*a*((23/12)*y -(4/3)*x + (5/12)))
#if/else method h=1/1000 a=-0.5 x=math.exp(h*a) y=math.exp(2*h*a) import sys sys.setrecursionlimit(3000) def recursion(n): if n == 1: return 1 elif n == 2: return x elif n == 3: return y elif n==4: return y+ h*a*((23/12)*y -(4/3)*x + (5/12)) print (recursion(1000))