This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Chapter 1 Iteration An investigation of fixed point iterations introduces the assignment statement, for and while loops, the plot function, and the Golden Ratio. Start by picking a number, any number. Enter it into Matlab by typing x = your number This is a Matlab assignment statement . The number you chose is stored in the variable x for later use. For example, if you start with x = 3 Matlab responds with x = 3 Next, enter this statement x = sqrt(1 + x) The abbreviation sqrt is the Matlab name for the square root function. The quantity on the right, √ 1 + x , is computed and the result stored back in the variable x , overriding the previous value of x . Now, repeatedly execute the statement by using the uparrow key, followed by the enter or return key. Here is what you get when you start with x = 3 . x = Copyright c 2009 Cleve Moler Matlab R is a registered trademark of The MathWorks, Inc. TM August 8, 2009 1 2 Chapter 1. Iteration 3 x = 2 x = 1.7321 x = 1.6529 x = 1.6288 x = 1.6213 x = 1.6191 x = 1.6184 x = 1.6181 x = 1.6181 x = 1.6180 x = 1.6180 These values are 3, √ 1 + 3, p 1 + √ 1 + 3, q 1 + p 1 + √ 1 + 3, and so on. After 10 steps, the value printed remains constant at 1.6180 . Try several other starting values. Try it on a calculator if you have one. You should find that no matter where you start, you will always reach 1.6180 in about ten steps. (Maybe a few more will be required if you have a very large starting value. Starting with numbers less than 1 makes things more complicated, but you might want to try it anyway.) Matlab is doing these computations to accuracy of about 16 decimal digits, but is displaying only five. You can see more digits by first entering format long and repeating the experiment. Here are the beginning and end of 30 steps starting at x = 3. x = 3 x = 2 x = 1.732050807568877 x = 1.652891650281070 3 .... x = 1.618033988749897 x = 1.618033988749895 x = 1.618033988749895 After about thirty or so steps, the value that is printed doesn’t change any more. You have computed one of the most famous numbers in mathematics, φ , the Golden Ratio . In Matlab , and most other programming languages, the equals sign is the assignment operator. It says compute the value on the right and store it in the variable on the left. So, the statement x = sqrt(1 + x) takes the current value of x , computes sqrt(1 + x) , and stores the result back in x . In mathematics, the equals sign has a different meaning. x = √ 1 + x is an equation . A solution to such an equation is known as a fixed point . (Be careful not to confuse the mathematical usage of fixed point with the computer arithmetic usage of fixed point .) Figure 1.1. Compute the fixed point by hand....
View
Full
Document
This note was uploaded on 10/11/2011 for the course MTHSC 365 taught by Professor Adams during the Spring '11 term at Clemson.
 Spring '11
 Adams
 matlab

Click to edit the document details