Finding products by for loop, MATLAB in Engineering

Finding products by for loop:

an illustration, when 5 is passed to be the value of the input argument n, the function will compute and return 1 + 2 + 3 + 4 + 5, or 15:

>> sum_1_to_n(5)

  ans =

    15

Note that the output was suppressed whenever initializing the sum to 0 and when adding to it throughout the loop.

The other very general application of a for loop is to find a running product. For illustration, rather than of finding the sum of the integers 1 through n, we can find the product of the integers 1 through n. Principally, we want to implement

501_Finding product by for loop1.png

or compute the product 1 * 2 * 3 * 4 *... * n, that is known as the factorial of n, written n!.

 

Posted Date: 10/19/2012 3:35:59 AM | Location : United States







Related Discussions:- Finding products by for loop, Assignment Help, Ask Question on Finding products by for loop, Get Answer, Expert's Help, Finding products by for loop Discussions

Write discussion on Finding products by for loop
Your posts are moderated
Related Questions
analyzing traffic; determine motion of flow; calculate tracklets; detect abnormalities;

Illustration of finding a sting: Let's enlarge this, and write a script which creates a vector of strings which are phrases. The outcome is not suppressed so that the string

Function rmfield - structure: The function rmfield eliminates a field from the structure. It returns a new structure with field eliminated, but does not modify the original st

Subfunctions: Though, it is possible to have more than one function in a given M-file. For illustration, if one function calls the other, the first function would be the prima

Evaluating a string: The function eval is used to compute a string as a function. For illustration, below is the string 'plot(x)'is interpreted to be a call to plot the functi

Solving 2 × 2 systems of equations: However this may be easy in a MATLAB, in normal finding solutions to the systems of equations is not. The systems which are 2 × 2 are, thou

Illustration of Gauss elimination: For illustration, for a 2 × 2 system, an augmented matrix be: Then, the EROs is applied to obtain the augmented matrix into an upper

Use of While loop: Here is an illustration of calling the function, passing 5000 for the value of the input argument high. >> factgthigh(5000) ans = 5040 The itera

Polyhedron - graphics objects: The field polyhedron.vertices is a matrix in which each row presents (x,y,z) points. The field polyhedron.faces defines the faces: for illustrat

Program to Counting in a while loop: The script initializes variable counter to 0. Then, in the while loop action, each and every time the user successfully enter a number, th