There are several problems in your code. First, your conditions are too complex, and casting something to double is unnecessary since that is Matlab's default data type anyway. Here's the cleaned-up code for the computation loop: for j = 2 : N if x(j - 1) < 0.5 x(j) =...