This is the result of an update made to the "sum" function through MATLAB R2020b, which was introduced to improve the performance/speed of the "sum" function. A snippet from the release notes is included below which may be causing the behavior you are seeing:
"The new algorithm reduces the amount of round-off error in calculations, which leads to a more accurate result in general. Therefore, the output of sum might change slightly in R2020b compared to R2020a when operating on numeric inputs, even though the results between the two versions are numerically equivalent."
The excerpt listed above is the reason that there is a small floating point difference between the "sum" and "cumsum" end results in R2020b and beyond. This difference is caused by precision limitations of floating-point arithmetic.
Some potential workarounds are listed below:
1. Round Answer:
The round function allows you to round off to a certain decimal place (ie. to 10 decimal places) which would retain accuracy while helping to cut out the floating-point error. This can be done using the "round" function as follows:
>> y = round(y(end), 10)
>> x = round(x, 10))
Additional documentation for the "round" function can be found here:
2. Compare Against a Tolerance:
A second option that can be used here is to compare these values against a decided tolerance (ie. 1e-10) to account for rounding errors caused by the limitations of floating-point arithmetic. This workflow typically works better when comparing two numbers that are slightly different due to a floating-point rounding error, and can be done as seen below:
>> abs(yy(end) - x)) < 1e-10
This will return “1” if the values are equal within the tolerance of 1e-10 and “0” otherwise. Note that the tolerance can be adjusted to whatever best helps represent the accuracy of your data.