Question
1. Machine epsilon, mach , is the smallest positive machine number such that 1 + eps > 1 . Matlab displays its value with >>
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started