def ellipse_err(polar_coords, params):
    'Calculates the total squared error of the data wrt an ellipse.\n\n       params is a 3 element array used to define an ellipse.\n       It contains 3 elements a,e, and t0.\n\n       a is the semi-major axis\n       e is the eccentricity\n       t0 is the angle of the major axis wrt the x-axis.\n\n       These 3 elements define an ellipse with one focus at origin.\n       Equation of the ellipse is r = a(1-e^2)/(1+ecos(t-t0))\n\n       The function calculates r for every theta in the data.\n       It then takes the square of the difference and sums it.\n\n       Arguments:\n       polar_coords: A list of polar coordinates in the format [radius,angle].\n       params: The array [a,e,t0].\n\n       Returns:\n       The total squared error of the data wrt the ellipse.'
    (a, e, t0) = params
    dem = (1 + (e * np.cos((polar_coords[:, 1] - t0))))
    num = (a * (1 - (e ** 2)))
    r = np.divide(num, dem)
    err = np.sum(((r - polar_coords[:, 0]) ** 2))
    return err
Calculates the total squared error of the data wrt an ellipse.

params is a 3 element array used to define an ellipse.
It contains 3 elements a,e, and t0.

a is the semi-major axis
e is the eccentricity
t0 is the angle of the major axis wrt the x-axis.

These 3 elements define an ellipse with one focus at origin.
Equation of the ellipse is r = a(1-e^2)/(1+ecos(t-t0))

The function calculates r for every theta in the data.
It then takes the square of the difference and sums it.

Arguments:
polar_coords: A list of polar coordinates in the format [radius,angle].
params: The array [a,e,t0].

Returns:
The total squared error of the data wrt the ellipse.
def ellipse_err(polar_coords, params):
    'Calculates the total squared error of the data wrt an ellipse.\n\n       params is a 3 element array used to define an ellipse.\n       It contains 3 elements a,e, and t0.\n\n       a is the semi-major axis\n       e is the eccentricity\n       t0 is the angle of the major axis wrt the x-axis.\n\n       These 3 elements define an ellipse with one focus at origin.\n       Equation of the ellipse is r = a(1-e^2)/(1+ecos(t-t0))\n\n       The function calculates r for every theta in the data.\n       It then takes the square of the difference and sums it.\n\n       Arguments:\n       polar_coords: A list of polar coordinates in the format [radius,angle].\n       params: The array [a,e,t0].\n\n       Returns:\n       The total squared error of the data wrt the ellipse.'
    (a, e, t0) = params
    dem = (1 + (e * np.cos((polar_coords[:, 1] - t0))))
    num = (a * (1 - (e ** 2)))
    r = np.divide(num, dem)
    err = np.sum(((r - polar_coords[:, 0]) ** 2))
    return err