Series using recursion

0

I'm trying to make a x^(n)/n! string but although it looks simple I have a constraint that is: It must be a recursive function. What I have so far that I do not even know if it is correct is the following:

def serie(x,n):
    if (x and n) < 0:
        return 0
    elif n = 0:
        return 1
    else:

Basically the main thing is that I'm not even realizing how I'm going to do it.

Basically my idea would be to multiply x by itself n times using perhaps a for or a range (although I do not know if I can use the range command when I'm working with recursion) and then divide by n factorial I was thinking of doing n*n-1*n-2 ....

Until I get to 0 but in this part I have no idea how to do it.

    
asked by anonymous 07.01.2016 / 00:30

1 answer

0

You can rewrite the operation serie(x, n) = x^n / n! as

x^n   x * x^(n-1)    x    x^(n-1)    x
--- = ----------- = --- * ------- = --- * serie(x, n - 1)
 n!   n * (n-1)!     n     (n-1)!    n

For values of n > = 1. The last expression shows the recursive step of its function.

    
07.01.2016 / 01:55