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
function numden: The function numden will return individually the numerator & denominator of a symbolic expression: >> sym(1/3 + 1/2) ans = 5/6 >> [n, d] =

Creating the structure Variables: Creating a structure variable can be accomplished by simply storing the values in fields by using assignment statements, or by using the stru

Function cirarea - Anonymous functions: The function handle name is cirarea. The one argument is passed to the input argument radius. The body of the function is an expression

Defined a variable in work space: The variables defined in the script will become a part of the workspace: >> clear >> who >> mysummfile    15 >> who

Example Exit modular program: In the illustration below, the user  Chose the Limit; -   Whenever prompted for n, entered the two invalid values before finally ente

Gauss Elimination: The Gauss elimination technique consists of:    Generating the augmented matrix [A b]    Applying EROs to augmented matrix to obtain an upper trian

Scaling:   change a row by multiplying it by a non-zero scalar sri →  ri For illustration, for the matrix:

Matrix definitions: As we know the matrix can be thought of as a table of values in which there are both rows and columns. The most common form of a matrix A (that is sometime

1. Write a MATLAB function (upperTriangle) using the functions you previously created to convert a matrix to upper triangular form. Start with row 1, column1. Find the row that has

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