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

Recursive functions, Recursive Functions: The Recursion occurs wheneve...

Recursive Functions: The Recursion occurs whenever something is defined in terms of itself. In the programming, a recursive function is a function which calls itself. The Recu

Illustration of variance, Illustration of Variance For illustration, fo...

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

Illustration of logical built-in functions, Illustration of logical built-i...

Illustration of logical built-in functions: The function find returns the indices of a vector which meet certain criteria. For illustration, to find all the elements in a vect

Three-dimensional pie and bar, Three-dimensional pie and bar: For the ...

Three-dimensional pie and bar: For the bar3 function, x & y vectors are passed and the function displays three-dimensional bars as shown in figure: Figure: Three-dimen

Illustration of a recursive function, Illustration of a recursive function:...

Illustration of a recursive function: illustration is of a recursive function which does not return anything, but simply prints. The below function prtwords receives a sentenc

Dimensions - matrix, Dimensions - matrix: The size and length function...

Dimensions - matrix: The size and length functions in the MATLAB are used to find array dimensions. Length function returns the number of elements in the vector. The size func

Naive Gauss Reduction, Write a MATLAB function [d1, u1, l1, c1, r1] = Naive...

Write a MATLAB function [d1, u1, l1, c1, r1] = NaiveGaussArrow(d, u, l, c, r) that takes as input the 5 vectors de ned above representing A. This function performs Naive Gauss redu

Differentiation, Differentiation: The derivative of a function y = f(x...

Differentiation: The derivative of a function y = f(x) can be written as follows or f  '(x) and is defined as the rate of change of the dependent variable y with respe

Logical vectors, Logical Vectors: The relational operators can also be...

Logical Vectors: The relational operators can also be used with the vectors and matrices. For illustration, let's say that there is a vector, and we want to compare each eleme

Standard deviation, Standard Deviation The standard deviation is the sq...

Standard Deviation The standard deviation is the square root of variance: The built-in function in a MATLAB for the standard deviation is known as std; the standard dev

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