It seems like you are facing an issue with the condition not being met when you make the altitude range smaller. One possible reason for this behavior could be the discrete nature of the simulation, where the altitude might not exactly match the specified range at each time step. To overcome this issue, you can introduce a tolerance in your condition to account for small deviations in the altitude.
Instead of using strict inequality, you can modify your condition as follows:
if (r(3) > 1000 - tolerance) && (r(3) < 1500 + tolerance)
beta = beta_0;
else
beta = 0;
end
Here, tolerance is a small positive value that allows for some flexibility in the altitude condition. You can experiment with different values of tolerance to find a suitable range that captures the desired altitude range accurately.
By introducing this tolerance, you can account for small deviations in the altitude and ensure that the condition is met within the desired range, even if the exact altitude is not reached at each time step.