def unpack_state(x, nR, nZ):
    """Unpack the state vector x into R_lmn, Z_lmn, L_lmn components.

    Parameters
    ----------
    x : ndarray
        vector to unpack: x = [cR, cZ, cL]
    nR : int
        number of R_lmn coefficients
    nZ : int
        number of Z_lmn coefficients

    Returns
    -------
    R_lmn : ndarray
        spectral coefficients of R
    Z_lmn : ndarray
        spectral coefficients of Z
    L_lmn : ndarray
        spectral coefficients of lambda

    """
    R_lmn = x[:nR]
    Z_lmn = x[nR : nR + nZ]
    L_lmn = x[nR + nZ :]
    return R_lmn, Z_lmn, L_lmn