the smallest positive, normalized element (ε0) f = [2, -5, 5, 4] in matlab

The smallest positive, normalized element ε0 is the minimum positive value that can be represented in floating point arithmetic. In MATLAB, we can find it using the realmin function:

main.m
f = [2, -5, 5, 4];
eps0 = realmin('single');
n_eps0 = eps0 / 2;

while (1 + n_eps0/2 > 1)
    n_eps0 = n_eps0 / 2;
end

f_norm = f * n_eps0;
141 chars
10 lines

In this code snippet, we first assign the input vector f = [2, -5, 5, 4]. Then, we use the realmin function to find the smallest positive normalized value that can be represented in MATLAB single precision floating point arithmetic. This value is stored in the variable eps0.

We then initialize a variable n_eps0 to be half of eps0. We then halve n_eps0 until 1+n_eps0/2 is equal to 1. This ensures that we find the smallest possible normalized value.

Finally, we multiply each element of f with n_eps0 to normalize it. The resulting normalized vector is stored in the variable f_norm.

related categories

gistlibby LogSnag