function eps02f clc; kmax = 100; fprintf('Approximation for 3 Decimal Digit Machine Epsilon:') eps0 = 1./100; eps1 = f02d(eps0 + 1); for k = 1:kmax epssv = eps0; eps1sv = eps1; ks = k - 1; eps0 = 1./100-(k-1)*(1./10^3); % subtracting .001 has too much truncation eps1 = f02d(eps0 + 1); fprintf('\n k = %4i; eps0 = %f; eps0+1 = %f;',k,eps0,eps1) if eps1 <= 1.e0 break; end end fprintf('\nApproximation Answer for 3 Decimal Digit Precision:') fprintf('\n k = %4i; epssv = %f; epssv+1 = %f;', ks, epssv, eps1sv) prec = 1-log(epssv)/log(10.); % find prec if maceps = 10^(1-prec); fprintf('\nprecision = %f decimal digits', prec) fprintf('\nCheck It Out!!!?:') fprintf('\n eps0 = %15.7e; 1+eps0 = %f; BUT 100.5-(1+0.005)*100 = %e' ... ,eps0,1+eps0,100.5-(1+0.005)*100) fprintf('\nIs the Class Theoretical Value?:') % check for rounding through refinement: fprintf('\n\nRounding Test Data:') eps0 = 0; deleps = 10^(-prec); % start with bisection maceps/4; fprintf('\n deleps = %f;', deleps); for k = 1:15 eps0 = eps0 + deleps; eps1 = f02d(eps0 + 1); fprintf('\n k = %4d; eps0 = %f; eps0+1 = %f', k, eps0, eps1) end fprintf('\nIs Rounding or Chopping Demonstrated?:\n') % end MATLAB main function % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % function y = f02d(x) y = round(x*10^2)/10^2; %=================================OUTPUT===================================== %>> Approximation for 3 Decimal Digit Machine Epsilon: % k = 1; eps0 = 0.010000; eps0+1 = 1.010000; % k = 2; eps0 = 0.009000; eps0+1 = 1.010000; % k = 3; eps0 = 0.008000; eps0+1 = 1.010000; % k = 4; eps0 = 0.007000; eps0+1 = 1.010000; % k = 5; eps0 = 0.006000; eps0+1 = 1.010000; % k = 6; eps0 = 0.005000; eps0+1 = 1.000000; %Approximation Answer for 3 Decimal Digit Precision: % k = 5; epssv = 0.006000; epssv+1 = 1.010000; %precision = 3.221849 decimal digits %Check It Out!!!?: % eps0 = 5.0000000e-003; 1+eps0 = 1.005000; BUT 100.5-(1+0.005)*100 = 1.421085e-014 %Is the Class Theoretical Value?: % %Rounding Test Data: % deleps = 0.000600; % k = 1; eps0 = 0.000600; eps0+1 = 1.000000 % k = 2; eps0 = 0.001200; eps0+1 = 1.000000 % k = 3; eps0 = 0.001800; eps0+1 = 1.000000 % k = 4; eps0 = 0.002400; eps0+1 = 1.000000 % k = 5; eps0 = 0.003000; eps0+1 = 1.000000 % k = 6; eps0 = 0.003600; eps0+1 = 1.000000 % k = 7; eps0 = 0.004200; eps0+1 = 1.000000 % k = 8; eps0 = 0.004800; eps0+1 = 1.000000 % k = 9; eps0 = 0.005400; eps0+1 = 1.010000 % k = 10; eps0 = 0.006000; eps0+1 = 1.010000 % k = 11; eps0 = 0.006600; eps0+1 = 1.010000 % k = 12; eps0 = 0.007200; eps0+1 = 1.010000 % k = 13; eps0 = 0.007800; eps0+1 = 1.010000 % k = 14; eps0 = 0.008400; eps0+1 = 1.010000 % k = 15; eps0 = 0.009000; eps0+1 = 1.010000 %Is Rounding or Chopping Demonstrated?: %>>