Math 171 - Alexiades
Lab 5
Machine epsilon

1. Machine epsilon, εmach, is the smallest positive machine number such that 1 + eps > 1 .
  Matlab displays its value with   >> eps (so, we should not use "eps" as variable name). Let's call it  ep  for short.
  It can be computed by starting with ep = 1 , and keep dividing it by 2, as long as 1 + ep > 1 . Then print the value.
  This can be implemented in various ways:
  A. using a for-loop
  B. using a while-loop
  Figure out the logic and algorithm ON PAPER first, especially what condition should be tested in each method.

2. To do:   Write Matlab function programs to implement each of the above ways.
  a. Function machepsA.m implementing method A above (for-loop).
  b. Function machepsB.m implementing method B above (while-loop).
Note: No input is needed here, so the functions will have blank argument ( ).
  • Each one should count how many times ep is divided by 2 (so at the end,   ep = 1/2n )
      and should print the method used, value of ep found, and the power n (as integer!).
      e.g. the code for method A, should print:
          A. using for-loop:   ep = VALUE , n = VALUE
  • For debugging, should print ep and n inside the loop, then comment it out.

    3. Prepare Lab5.txt for submission:
  • >> diary Lab5.txt
  • % Name, Date, Lab5
  • then insert your machepsA.m code (remember how? >> type machepsA.m),
      and a demarkation line:   % ------------------------------------------------
      then run the function, then a separator:
    % ==================================================
  • Then similarly for the other function, and
    % ==================================================
  • Then answer the questions (label each by 1.,2.,...):
      1. Did both codes produce the same value for ep ?
      2. The same power n ?  
      3. Does your ep match Matlab's eps ?
      4. If not, which one is right? Test it!
  • >> diary off
  • Using a PLAIN TEXT editor edit the file Lab5.txt to clean it up, leaving only the correct version of what's asked for in this Lab.

    Then submit it on Canvas.