Just use the function name itself - in this case, R
- and call it the same way you call it from outside.
for other algorithms that can be calculated with recursion, such as factorial, it is easier to understand:
def factorial(n):
if n == 1:
return 1
return n * factorial(n - 1)
With the notation used, and since I don’t know the function, I can’t understand what you want to calculate with your function to be able to rewrite it recursively.
The way it’s written there, you call R
recursively with the value (1/x+2/x)
but x
and uam global variable defined outside the function - therefore except in a single special case, x
will never equal 1, and its function will never reach the stop value - the function will only terminate recursion, and start returning the values, when called with the value "1".
And even if you swap "x" for "n" in the call to R on the line return 1/1/x-1/R(1/x+2/x)*n/1*n
, i don’t think the expression "1/x + 2 / x" will converge to "1" - this only happens with the value "3" in x - so I think you need to explain better the formula you want to calculate recursively if you want more help than this.
had to mount recursive and iterative transform but I did code but I don’t know where to call function? ai bug all
– adriana
What the function
R
should do ?– ThiagoO
1/1/x-1/3/x-1 if repair grows 2/x every iteration ai should calculate this
– adriana
Your question is how to define the stop condition of the recursive call ?
– ThiagoO
Or how to invoke the function while executing it?
– ThiagoO
exactly that invoke function
– adriana
You could better detail the question, using the [Edit] button, what exactly your function should do and what is currently happening?
– Woss
You have an undeclared x variable within your function. I don’t understand that you are calculating. Variable x read out of function is not passed to function.
– Ken