% explore_eps.m % k. stewart spring 1998 - written for CS 205 % we want to examine the behavior of the floating point % number system % % assuming no background or familiarity with floating point % behavior, we'll examine first a finite list of values % % it's dangerous to use the variable named "eps" since this is % predefined MATLAB value which the user can reset % u = 1/2^15; % start the search off at an arbitrary, but exact, binary value formax = 40; for i=1:formax if (1.0 + u > 1.0) fprintf('For u = %12.8g 1.0+u> 1.0 \n',u) else fprintf('Finally, after %4.0f iterations we find that\n',i) fprintf(' for u = %12.8g 1.0+u is NOT > 1.0 \n',u) fprintf(' therefore unit roundoff is %12.8g\n',2*u) fprintf(' Break out of the for loop\n') break; end % if-else block u = u/2; if (i == formax) fprintf('Used %g loop iterations without finding u\n',formax) end end % for i=1:10 loop