def Solver_CMFR_N(t_data, C_data, theta_guess, C_bar_guess):
    """Use non-linear least squares to fit the function
    Tracer_CMFR_N(t_seconds, t_bar, C_bar, N) to reactor data.

    :param t_data: Array of times with units
    :type t_data: float list
    :param C_data: Array of tracer concentration data with units
    :type C_data: float list
    :param theta_guess: Estimate of time spent in one CMFR with units.
    :type theta_guess: float
    :param C_bar_guess: Estimate of average concentration with units ((mass of tracer)/(volume of one CMFR))
    :type C_bar_guess: float

    :return: tuple of

        * **theta** (*float*)- Residence time in seconds
        * **C_bar** (*float*) - Average concentration with same units as C_bar_guess
        * **N** (*float*)- Number of CMFRS in series that best fit the data
    """
    C_unitless = C_data.magnitude
    C_units = str(C_bar_guess.units)
    t_seconds = (t_data.to(u.s)).magnitude
    # assume that a guess of 1 reactor in series is close enough to get a solution
    p0 = [theta_guess.to(u.s).magnitude, C_bar_guess.magnitude,1]
    popt, pcov = curve_fit(Tracer_CMFR_N, t_seconds, C_unitless, p0)
    Solver_theta = popt[0]*u.s
    Solver_C_bar = popt[1]*u(C_units)
    Solver_N = popt[2]
    Reactor_results = collections.namedtuple('Reactor_results','theta C_bar N')
    CMFR = Reactor_results(theta=Solver_theta, C_bar=Solver_C_bar, N=Solver_N)
    return CMFR
def Solver_CMFR_N ( t_data , C_data , theta_guess , C_bar_guess ) : C_unitless = C_data . magnitude C_units = str ( C_bar_guess . units ) t_seconds = ( t_data . to ( u . s ) ) . magnitude p0 = [ theta_guess . to ( u . s ) . magnitude , C_bar_guess . magnitude , 1 ] popt , pcov = curve_fit ( Tracer_CMFR_N , t_seconds , C_unitless , p0 ) Solver_theta = popt [ 0 ] * u . s Solver_C_bar = popt [ 1 ] * u ( C_units ) Solver_N = popt [ 2 ] Reactor_results = collections . namedtuple ( 'Reactor_results' , 'theta C_bar N' ) CMFR = Reactor_results ( theta = Solver_theta , C_bar = Solver_C_bar , N = Solver_N ) return CMFR
Use non-linear least squares to fit the function
    Tracer_CMFR_N(t_seconds, t_bar, C_bar, N) to reactor data.

    :param t_data: Array of times with units
    :type t_data: float list
    :param C_data: Array of tracer concentration data with units
    :type C_data: float list
    :param theta_guess: Estimate of time spent in one CMFR with units.
    :type theta_guess: float
    :param C_bar_guess: Estimate of average concentration with units ((mass of tracer)/(volume of one CMFR))
    :type C_bar_guess: float

    :return: tuple of

        * **theta** (*float*)- Residence time in seconds
        * **C_bar** (*float*) - Average concentration with same units as C_bar_guess
        * **N** (*float*)- Number of CMFRS in series that best fit the data