Example of recursive functions, MATLAB in Mathematics

Example of Recursive functions:

This definition is recursive as a factorial is defined in terms of the other factorial. There are two parts to any recursive definition: the common or inductive case, and the base case. We say that in common the factorial of n is defined as n multiplied by the factorial of (n - 1), but the base case is that the factorial of 1 is 1. The base case stops the recursion.

For illustration,

3! = 3 * 2!

2! = 2 * 1!

          1! = 1

= 2

= 6

The way it works is that 3! is defined in terms of the other factorial, as 3 * 2!. This expression cannot yet be computed, as first we have to find out the value of 2!. Therefore, in trying to compute the expression 3 * 2!, interruption by recursive definition occurs. According to the definition, 2! be 2 * 1!. And again, the expression 2 * 1! cannot yet be computed as first we have to find the value of 1!. According to the definition, 1! be 1. As we now know what 1! is, we can carry on with the expression which was just being computed; now we know that 2 * 1! is 2 * 1, or 2. Therefore, now we can finish the earlier expression which was being computed; now we know that 3 * 2! is 3 * 2, or 6.

This is the approach that recursion always works. By recursion, the expressions are place on hold with interruption of the common case of the recursive definition. This keeps occurring until finally the base case of the recursive definition applies. This at last stops the recursion, and then the expressions which were put on hold are computed in the reverse order. In this situation, first the computationof 2 * 1! was done, and then 3 * 2!.

There should always be a base case to end the recursion, and the base case should be reached at several points. Or else, infinite recursion would occur (theoretically, though MATLAB will stop the recursion ultimately).

Posted Date: 10/22/2012 1:29:26 AM | Location : United States







Related Discussions:- Example of recursive functions, Assignment Help, Ask Question on Example of recursive functions, Get Answer, Expert's Help, Example of recursive functions Discussions

Write discussion on Example of recursive functions
Your posts are moderated
Related Questions
Strings as Vectors: The Strings are considered as vectors of characters-or in another words, a vector in which each and every element is a single character-so numerous vector

Example of Symbolic Expression When there is more than one variable, the MATLAB selects which to solve for. In the illustration below, the equation ax 2 + bx = 0 is solved. Th

Illustration of Empty vectors: The Empty vectors can also be used to delete elements from the arrays. For illustration, to remove the third element from array, an empty vector

Plot types: Besides plot and bar, there are another plot types like stem plots, histograms, stem plots, area plots and pie charts, and also other functions which customize the

Function isreal - complex numbers: The function isreal returns 1 for logical true when there is no imaginary part of the argument, or 0 for false when the argument does have a

Fliplr function: The fliplr function "flips" the matrix from left to right (in another words the left-most column, the first column, become the last column and so on), and the

Complex numbers: A complex number is commonly written in the form z = a + bi here a is known as the real part of the number z, b be the imaginary part of z, and i is √-1

Built in recursive function in MATLAB: We have seen that the built-in function in MATLAB to compute factorials, termed as the factorial and we know how to implement the iterat

Error-Checking for Integers: As MATLAB uses the type double by default for all the values, to check to make confirm that the user has entered an integer, the program have to c

Illustration of Variance For illustration, for the vector [4, 6, 1, 5], there are n = 4 values therefore n - 1 is 3. The mean of this data set is also 4. The variance will be