HW029
Math 2984 - Fall 2017
Intro to Mathematical Problem Solving


TASK: Approximate the golden ratio, by computing a sequence.


COMMENT: The golden ratio describes the relationship between the width and height of a rectangle whose shape was admired by the ancient Greeks.

If we symbolize the ratio by "phi", then the exact value is

        phi = ( 1 + sqrt ( 5 ) ) / 2
      
which is approximately 1.618.

There is a sequence of numbers that gets closer and closer to phi. The rule for writing down the sequence is as follows:

  1. A(0) = 1;
  2. A(i) = 1 + 1 / A(i-1)

Using these rules, the first elements of the sequence are:

        #0: 1
        #1 = 1 + 1/#0 = 1 + 1/1 = 2.
        #2 = 1 + 1/#1 = 1 + 1/2 = 1.5.
        #3 = 1 + 1/#2 = 1 + 1/1.5 = 1.66...
        #4 = 1 + 1/#3 = 1 + 1/1.66... = 1.6
      

We would like to compute an element of this sequence that is very close to the value of phi. We will guess that the sequence elements zigzag above and below phi. If that is true, then the difference between two successive elements gives us an overestimate of our error.

Strategy: to estimate phi to an error less than ACC, compute elements of the sequence until the absolute value of the difference between two successive elements is less than ACC. Report the number of steps taken, and the estimate.


INSTRUCTIONS:

        We are only going to remember the most recent two elements in the
        sequence.  A will be the newest value, and AOLD the previous one.

        Get ACC, the requested accuracy, from a user INPUT statement.

        Initialize I to 0

        Set up a "Do Forever" WHILE loop

          if I is 0
            set AOLD to 0
            set A to 1
          otherwise
            set AOLD to A
            set A to the next element of the sequence

          Estimate the error, ERR_EST

          if ERR_EST is below your accuracy, leave the loop

          Otherwise, increase I and try again

        Print the number of steps taken, I
        Print your estimate of PHI
        Print your estimate of the error, ERR_EST
      


CHECK: Here's an example of results. I added some statements to my program to print the exact value of PHI, and the exact error, although you don't have to do that.

>> hw029
  Enter desired accuracy: 0.001

Number of steps was 9
Estimated PHI =    1.618181818181818
Estimated Error = 5.3476e-04

Exact     PHI =    1.618033988749895
Exact     Error = 1.4783e-04
>> 
      


SUBMIT: Your work should be stored in a script file called "hw029.m". Your script file should begin with at least three comment lines:

        % hw029.m
        % YOUR NAME
        % This script (describe what it does)
        % Add any comments here that you care to make.
      
If this problem is part of an assignment, then submit it to Canvas.