Example of recursive functions, MATLAB in Mathematics

Assignment Help:

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).


Related Discussions:- Example of recursive functions

Illustration of writing variables to a file, Illustration of Writing variab...

Illustration of Writing variables to a file: For illustration, in the below session in the Command Window, 3 variables are generated; these are then exhibited using who. Then,

Creating customized strings, Creating Customized strings: There are ma...

Creating Customized strings: There are many built-in functions which create customized strings, including blanks, char, and sprintf. We know that the char function can be u

Strings as vectors, Strings as Vectors: The Strings are considered as ...

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

Structure consisting of the fields, Structure Consisting of the Fields ...

Structure Consisting of the Fields A MATLAB can also solve the sets of equations. In this illustration, the solutions for x, y, & z are returned as a structure consisting of th

Example of logical built-in functions, Example of Logical built-in function...

Example of Logical built-in functions: For equivalent to all the function, we should make sure that the entire elements in the vector are logically true. The one way of doing

Example of minimum and maximum value, Example of Minimum and Maximum Value ...

Example of Minimum and Maximum Value For matrices, the functions min and max operate column wise by the default: >> mat = randint(2,4,[1 20]) mat =    9   10   1

Optimal foraging theory, This project requires you to use the ideas of Chap...

This project requires you to use the ideas of Chapter 25 regarding maximization of a function. Here we assume that evolution has acted to generate highly efficient foragers. By hig

Sprintf function, sprintf function: The sprintf function works precise...

sprintf function: The sprintf function works precisely like the fprintf function, but rather than printing it generates a string. Here are some illustrations in which the outp

Function xlsread - file function, Function xlsread - file function: Th...

Function xlsread - file function: The function xlsread will read from the spreadsheet file. For illustration, to read from file just generated: >> ssnums = xlsread('ranexc

Morphological reconstruction, how can reconstruct just part of an image usi...

how can reconstruct just part of an image using imreconstruct?

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd