Recursive functions are those functions that call themselves. A perfect example of a recursive function is the factorial function:
factorial(n)=n*factorial(n-1)
You can define the above function by taking advantage of the conditions like this:
factorial(n)=n*factorial(n-1); n>1 factorial(n)=1; n=1
The last condition is optional. An alternative is to simply omit it like this:
factorial(n)=n*factorial(n-1); n>1 factorial(n)=1
If you omit the condition of a function, the program will call that function only if none of the previous functions had their condition met.
With above function defined, if you call factorial(5), it will be evaluated like this:
factorial(5)=5*factorial(4) factorial(4)=4*factorial(3) factorial(3)=3*factorial(2) factorial(2)=2*factorial(1) factorial(1)=1
Once the program reaches the 5th step it gets a concrete value 1 it then substitutes back in 4th step to complete that step. It then uses the value of 4th step to revalue step 3 and so on.
The following demonstrates how the Taylor Polynomial series T(n,x) consists of n fractions:
The function e^x can be approximated by a Taylor Polynomial series. Here the Taylor Polynomial can be defined recursively:
T(n,x)=T(n-1,x)+x^n/n!; n>=1 T(n,x)=1; n<1
To find a good approximation of e^99 a series of 10 terms should be sufficient, so simply call T function like this:
T(10,99)