def get_eccentric_anomaly_old(M, e):
    """
    Get the eccentric anomaly (E) from the mean anomaly (M) and orbital eccentricity (e)
    Uses the equation M = E - esinE
    """
    if HelperFunctions.IsListlike(M):
        return [get_eccentric_anomaly(Mi, e) for Mi in M]

    chisquare = lambda E: (E - e * np.sin(E) - M)**2

    output = minimize_scalar(chisquare, bounds=[0, 2 * np.pi], method='brent')
    return output.x
def get_eccentric_anomaly(M, e):
    """
    Get the eccentric anomaly (E) from the mean anomaly (M) and orbital eccentricity (e)
    Uses the equation M = E - esinE
    """
    if HelperFunctions.IsListlike(M):
        return [get_eccentric_anomaly(Mi, e) for Mi in M]

    func = lambda E: E - e * np.sin(E) - M
    dfunc = lambda E: 1.0 - e * np.cos(E)
    d2func = lambda E: e * np.sin(E)

    output = newton(func, np.pi, fprime=dfunc, fprime2=d2func)

    #output = minimize_scalar(chisquare, bounds=[0, 2*np.pi], method='brent')
    return output