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.m141 chars10 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
.
gistlibby LogSnag