Math 171 - Alexiades
Lab 1
Machine epsilon

1. Machine epsilon, εmach, is the smallest positive machine number such that 1 + eps > 1 .
  Matlab displays its value with   >> eps (so cannot use "eps" as variable name). Let's call it  e  for short.
  It can be computed by starting with e = 1 , and keep dividing it by 2, as long as 1 + e > 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 case. Then try it on Matlab.

2. To do:   Write a script (or function) to implement each of the above ways.
  a. Script machepsA.m implementing method A above.
  b. Script machepsB.m implementing method B above.
  • Each one should count how many times e is divided by 2 (so at the end,   e = 1/2n )
      and print the method used, value of e found, and the power n (as integer!).
      E.g. the code for method A, should print:
          A. using for-loop :   e = VALUE , n = VALUE

    3. Prepare Lab1.m for submission:
  • In a plain text file, insert your % Name, % Date, % Lab1 (as comments).
  • then insert the "machepsA.m" code, then a demarkation line:   % ------------------------------------------------
  • Then similarly insert the other script.
  • And insert: matlab_eps = eps to see what Matlab gives.
  • Then a demarkation line:   % ==============================================
  • Run "Lab1.m" and answer the questions:
      1. Did both methods produce the same value for e ?
      2. The same power n ?  
      3. Does your e match Matlab's eps ? Explain the difference, and fix your script.
      Insert your answers in "Lab1.m" as comments, at the bottom.
  • Clean up the script file (in the editor) leaving ONLY what's asked for in this lab. Run it again to make sure it runs.

    4. Publish and submit:
  • Now, "publish" it into a PDF file:   >> publish('Lab1.m', 'pdf' )
      This will insert the script, will run it, and will include its output into "Lab1.pdf".
      The "Lab1.pdf" file will be inside the "html" folder on left panel. Check that it contains what it should.
      You can copy the file to your desktop so you can upload it on Canvas.
  • Finally, go to Canvas > Assignments > LABS > Lab1,   and Upload your "Lab1.pdf" file by the Due date and time.