def vdecomp(v, m=None, minlen=None, maxlen=None):
    """
    Decompose a vector into components. an nD stack of m-element vectors will return a tuple with up to m elements,
    each of which will be an nD stack of scalars

    :param v: nD stack of m-element vectors, a numpy (n+1)D array with shape
        (n_stack0,n_stack1,...,n_stackn-2,m,n_stackn-1)
    :param minlen: If passed, this will pad out the returned vector components with zero scalars
        such that the returned tuple has minlen components. We do zero scalars rather than zero arrays
        of the same size as the other components to save memory, since a scalar is compatible by
        broadcasting with an array of any size.
    :param maxlen: If passed, this will restrict the returned vector components to the given
        size, even if the input vector has more components.
    :param m: If passed, treat the input as if it were an nD stack of m-element vectors. If the actual
              stack has more components, don't return them. If it has less, return scalar zeros for the
              missing components
    :return: A tuple. Each element is a vector component. Vector components pulled from the vector will be
        an nD stack of scalars, a numpy nD array with shape (n_stack0,n_stack1,...,n_stackn-2,n_stackn-1).
        Vector components which are made up will be scalar zeros.

    Note: If you pass maxlen<minlen, the result is still well-defined, since the maxlen is used first,
          then the minlen. If you pass a vector with m=4, a minlen of 7, and a maxlen of 2, you will get
          a result with the first two components of the vector, followed by 5 zeros. I'm not sure if this
          is useful, but there it is.
    Example:
        v=np.zeros((24,3,50)) #Suitable for holding multiple trajectories

        #OR

        v0=np.zeros((3,50)) #Initial conditions for 50 trajectories

        t=np.arange(24)     #Time steps

        v=rk4(x0=v0,t=t)    #Numerically integrate multiple trajectories. Result shape will be (t.size,)+v0.shape,

                            #IE (24,3,50)

        x,y,z=vcomp(v) #after this, x, y, and z are each numpy arrays of shape (24,50)

    """
    if maxlen is None and m is not None:
        maxlen = m
    if minlen is None and m is not None:
        minlen = m
    ndStack = len(v.shape) > 2
    efflen = v.shape[-2 if ndStack else 0]
    if maxlen is not None and maxlen < efflen:
        efflen = maxlen
    result = tuple([v[..., i, :] if ndStack else v[i, ...] for i in range(efflen)])
    if minlen is not None and minlen > efflen:
        result = result + (0,) * (minlen - efflen)
    return result