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
Sort algorithm for Sorting vectors of structures: Note that only the price field is compared in the sort algorithm, but the whole structure is replaced. That is therefore each

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

Replacement : Replace a row by adding it to (or subtract from it) a multiple of the other row. For a given row ri, this is written as   ri  - srj →  ri Note that when r

I dont know how to input different videos on matlab program

I have a 400x2 vel.dat and 20x2 xy.dat file, how can i plot a streamslice graph on matlab with this two files.

Illustration of Subfunctions: This is an illustration of running this program: >> rectarea Please enter the length: 6 Please enter the width: 3 For a rectan

Calling of Function polyval: The curve does not appear very smooth on this plot, but that is as there are only five points in the x vector. To estimate the temperature

Illustration of gauss-jordan: Here's an illustration of performing such substitutions by using MATLAB >> a = [1 3 0; 2 1 3; 4 2 3] a = 1 3 0 2 1 3 4 2

Technique is to create one element - vector: Technique is to create one element with the values from one structure, and use repmat to replicate it to the preferred size. Then,

Algorithm for expfn function: The algorithm for expfn function is as shown:  receives the value of x as the input argument.  Prints the value of exp(x).  assigns a