Transcription of Chapter 1 Iteration - MathWorks
{{id}} {{{paragraph}}}
Chapter 1 IterationIteration is a key element in much of technical computation. Examples involving theGolden Ratio introduce theMatlabassignment statement,forandwhileloops,and by picking a number, any number. Enter it intoMatlabby typingx =your numberThis is aMatlabassignment statement. The number you chose is stored in thevariablexfor later use. For example, if you start withx = 3 Matlabresponds withx =3 Next, enter this statementx = sqrt(1 + x)The abbreviationsqrtis theMatlabname for the square root function. Thequantity on the right, 1 +x, is computed and the result stored back in the variablex, overriding the previous value on your computer keyboard, probably in the lower right corner,you should be able to find four arrow keys. These are thecommand line up-arrow key allows you to recall earlier commands, including commands fromCopyrightc 2011 Cleve MolerMatlabR is a registered trademark of MathWorks , 2, 201112 Chapter 1.
6 Chapter 1. Iteration produces 32 lines of output, one from the initial statement and one more each time through the loop. A while loop executes a block of code an unknown number of times. Termi-nation is controlled by a logical expression, which evaluates to true or false. Here is the simplest while loop for our fixed point iteration. x = 3
Domain:
Source:
Link to this page:
Please notify us if you found a problem with this document:
{{id}} {{{paragraph}}}