def hamiltonian_c(n_max, in_w, e, d):
    """apply tridiagonal real Hamiltonian matrix to a complex vector
    
    Parameters
    ----------
    n_max : int
        maximum n for cutoff
    in_w : np.array(complex)
        state in
    d : np.array(complex)
        diagonal elements of Hamiltonian
    e : np.array(complex)
        off diagonal elements of Hamiltonian
    
    Returns
    -------
    out_w : np.array(complex)
        application of Hamiltonian to vector
    """
    n_max = int(n_max)
    out_w = in_w[:n_max]*d[:n_max]
    out_w[:(n_max-1)] += e[:(n_max-1)]*in_w[1:n_max]
    out_w[1:n_max] += e[:n_max-1] * in_w[:n_max-1]
        
    return out_w