% macheps.m 2011-11-14
% loop to determine machine epsilon
%
clear;clc;
disp(sprintf(' MATLAB example: macheps.m'));
%
kntmax = 60;   % maximum loop count
refnum = 1.0;  % starting value
%
epsilon = refnum;  % allows the loop to start at different values
icount = 0;        % initialise counter
while ( ( (epsilon + refnum) > refnum) & (icount <= kntmax) )
    epsilon = epsilon/2.0;
    icount = icount +1;
%
    disp(sprintf('%s %d %s %e', 'Icount is', icount,'Epsilon is',epsilon));
end %end of while loop

epsilon = epsilon*2.0;
disp(sprintf('%s %d %s %e', 'Icount is', icount,'Epsilon is',epsilon));
