Use of while loop, MATLAB in Engineering

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 iterator variable i is initialized to 0, and the running product variable fac that will store the factorial of each and every value of i, is initialized to 1. The first time the while loop is executed, the condition is theoretically true: 1 is less than or equal to 5000. Therefore, the action of the loop is executed, that is to increment i to 1 and fac to 1 (1 * 1). Afterward execution of the action of the loop, the condition is computed again. As it will still be true, the action is executed: i is incremented to 2, and fac get the value 2 (1 * 2). The value 2 is still   <= 5000, therefore the action will be executed again: i will be incremented to 3, & fac will get the value 6 (2 * 3). This continues till the first value of fac is found which is bigger than 5000. As soon as fac gets to this value, the condition become false and the while loop will end. At this point the factorial is assigned to the output argument that returns the value. The reason at which i is initialized to 0 instead of 1 is that the first time the loop action is executed, i will be 1 and fac becomes 1 so we have 1 and 1!, that is 1. Note that the output of all the assignment statements is suppressed in the function.


Posted Date: 10/19/2012 6:05:12 AM | Location : United States







Related Discussions:- Use of while loop, Assignment Help, Ask Question on Use of while loop, Get Answer, Expert's Help, Use of while loop Discussions

Write discussion on Use of while loop
Your posts are moderated
Related Questions
Converting between the String and Number types: The MATLAB has many functions which convert numbers to strings in which each character element is a separate digit, and vice ve

Square Matrices: If a matrix has similar number of rows and columns, for illustration, if m == n, the matrix is square matrix. The definitions which follow in this part apply

Technique to create Nested structures: This technique is the most proficient. Though, the other technique is to build the nested structure one field at a time. As this is a ne

Finding a sting - function strfind: The function strfind does necessarily similar thing, except that the order of the arguments does make dissimilarity. The common form is str

Passing Structures to Functions: The whole structure can be passed to a function, or separate fields can be passed. For illustration, here are the two distinct versions of a f

Illustration of gauss-jordan elimination: An illustration of interchanging rows would be r1 ¬→ r3, that would results: Now, beginning with this matrix, an illustration of sc

readlenwid function: function call: [length, width] = readlenwid; function header: function [l,w] = readlenwid In the function call, not any argument is passed; henc

I have a frequency response data. How do I convert that to state space? I am given a 6 row and 3 column data (steady state). How do i convert that to state space model?

Illustration of Set operations: For illustration, given the vectors as shown below: >> v1 = 2:6 v1 = 2  3  4  5  6 >> v2 = 1:2:7 v2 = 1  3  5  7

Use of built-in colormaps: MATLAB has built-in colormaps, it is also possible to generate others by using combinations of any colors. For illustration, the following generates