Assuming that we have the position values stored in a column vector pos
and the time values stored in a column vector time
, we can compute the mean position xm
as follows:
main.m113 chars6 lines
To find the largest time step dtm
that satisfies the condition xabs(xm) < 0.027
, we need to find the maximum time step between any two consecutive time values in the range [tmin, tmax]
. We can do this using the diff
function and taking the maximum of the absolute values of the resulting array:
main.m42 chars3 lines
Note that we're computing the absolute values of the time step array because we're interested in the maximum step size, regardless of whether it's positive or negative.
gistlibby LogSnag