The next four statements place text at various points the string phi denotes

The next four statements place text at various points

This preview shows page 6 - 9 out of 55 pages.

line in dashed blue. The next four statements place text at various points; the string \ phi’ denotes the Greek letter. The two axis statements cause the scaling in the x and y directions to be equal and then turn off the display of the axes. The last statement sets the background color of gcf , which stands for get current figure , to white. A continued fraction is an infinite expression of the form a 0 + 1 a 1 + 1 a 2 + 1 a 3 + ··· . If all the a k ’s are equal to 1, the continued fraction is another representation of the golden ratio: φ = 1 + 1 1 + 1 1+ 1 1+ ··· . The following Matlab function generates and evaluates truncated continued frac- tion approximations to φ . The code is stored in an M-file named goldfract.m . function goldfract(n) %GOLDFRACT Golden ratio continued fraction. % GOLDFRACT(n) displays n terms. p = ’1’; for k = 1:n p = [’1+1/(’ p ’)’]; end p p = 1; q = 1; for k = 1:n s = p; p = p + q; q = s; end p = sprintf(’%d/%d’,p,q)
Image of page 6
Image of page 7
8 Chapter 1.Introduction to MATLABprints the final fraction by formattingpandqas decimal integers and placing a ‘/between them.The thirdpis the same number as the first twop’s, but is represented asa conventional decimal expansion, obtained by having theMatlabevalfunctionactually do the division expressed in the secondp.The final quantityerris the difference betweenpandφ. With only 6 terms,the approximation is accurate to less than 3 digits. How many terms does it taketo get 10 digits of accuracy?
Image of page 8
Image of page 9

You've reached the end of your free preview.

Want to read all 55 pages?

  • Fall '13
  • Ivan
  • matlab, Gate, Fibonacci number, Golden ratio, magic squares

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture