rescale function does not work correctly
8 views (last 30 days)
Jack on 29 Mar 2023
Yes, it is a common issue in numerical computing due to the limitations of floating-point arithmetic. In floating-point arithmetic, numbers are represented with a finite number of bits, which can lead to rounding errors and inaccuracies in calculations.
In your case, the value of 1.1102e-16 is very close to zero, but it is not exactly zero. When you use the rescale function, it scales the elements of B so that the minimum value becomes 0 and the maximum value becomes 1. However, due to rounding errors in the computation, the minimum value of B may not be exactly zero, but rather a very small number close to zero.
When you apply the min function to the rescaled B, it returns the smallest value in the matrix, which is very close to zero but not exactly zero. The 'all' option specifies that the minimum value should be computed over all elements of the matrix.
To avoid this issue, you can use a tolerance value when comparing values to zero. For example, you could modify your code to check if the minimum value is within a certain tolerance of zero, like this:
tolerance = 1e-10; % set a tolerance value
min_val = min(rescale(B(:)));
if abs(min_val) < tolerance
disp('Minimum value is approximately zero');
disp('Minimum value is not approximately zero');
This code checks if the absolute value of the minimum value is less than the tolerance value. If it is, it displays a message indicating that the minimum value is approximately zero. Otherwise, it indicates that the minimum value is not approximately zero.