c = [0.004, 0.0087, 0.019, 0.024, 0.094, 0.195]
q = [0.026, 0.053 , 0.075, 0.082, 0.123, 0.129]
html('<h2>Solución</h2>')
datos_eq = zip(c,q)
%var c_A, q_A_max, K_Ac, n
L = 15
c0 = 1.30
M = 180.156
S1 = 20
q0 = 0
S2 = 20
c0 = c0*M/1000
html('<h3>Parte a) Ajustar a el modelo de Langmuir y Freundlich</h3>')
show("===== Isoterma de Langmuir =====")
qA_L(c_A) = q_A_max*K_Ac*c_A / (1+K_Ac*c_A)
ajuste = find_fit(datos_eq, qA_L, solution_dict = True)
qA_L = qA_L(q_A_max= numerical_approx(ajuste[q_A_max], digits = 4), K_Ac= numerical_approx(ajuste[K_Ac], digits=4))
show(r"$K_{A,c} = $ ", numerical_approx(ajuste[K_Ac], digits=4), r" L/kg; $q_{A,máx} = $", numerical_approx(ajuste[q_A_max], digits=4), " kg/kg")
show("$q_{A_L} = $", qA_L)
show("===== Isoterma de Freundlich =====")
qA_F(c_A) = K_Ac*c_A^(1/n)
ajuste = find_fit(datos_eq, qA_F, solution_dict = True)
qA_F = qA_F(n= numerical_approx(ajuste[n], digits=4), K_Ac=numerical_approx(ajuste[K_Ac], digits=4))
show(r"$K_{A,c} = $ ", numerical_approx(ajuste[K_Ac], digits=4), r" L/kg; $n = $", numerical_approx(ajuste[n], digits=4))
show("$q_{A_F} = $", qA_F)
gr_datos = scatter_plot(datos_eq, axes_labels = ['$c_A/(\\mathrm{kg/L})$', '$q_A/(\\mathrm{kg/kg})$'])
gr_Langm = plot(qA_L, xmin = 0, xmax = max(max(c),c0), thickness=2, legend_label = 'Langmuir', color = 'blue')
gr_Frlch = plot(qA_F, xmin = 0, xmax = max(c), thickness=2, legend_label = 'Freundlich', color = 'green')
show(gr_datos+gr_Langm+gr_Frlch)
html('<h3>Parte b) Una etapa</h3>')
def Calcula_etapa(W_L, W_S, c_entra, q_entra, q_isot):
R.<c_sale> = QQ[]
q_sale = q_isot(c_sale)
f = c_sale - (W_S/W_L * (q_entra - q_sale) + c_entra)
csale = find_root(f, 0, c_entra)
return [csale, q_sale(c_sale=csale)]
c1, q1 = Calcula_etapa(L, S1, c0, q0, qA_L)
show (r'$c_1 = %.3g$ kg/L; $q_1 = %.3g$ kg/kg' %(c1,q1))
gr_etapa1 = line([(c0,q0),(c1,q1)], color = 'purple', thickness=2, legend_label = 'Etapa 1') + line([(c1,q1),(c1,0)], color = 'purple', linestyle= '--') \
+ text("$c_0$", (c0, -0.005)) + text("$c_1$", (c1, -0.005)) + text("$ q = -\\frac{F}{S_1}(c-c_0)+q_0$", (0.15, 0.09), color = 'purple', fontsize = "large")
show(gr_datos+gr_Langm+gr_etapa1)
html('<h3>Parte c) Dos etapas a flujo cruzado, idénticas cantidades de sólido</h3>')
c2, q2 = Calcula_etapa(L, S2, c1, q0, qA_L)
show (r'$c_2 = %.3g$ kg/L; $q_2 = %.3g$ kg/kg' %(c2,q2))
gr_etapa2 = line([(c1,q0),(c2,q2)], color = 'magenta', thickness=2, legend_label = 'Etapa 2') + line([(c2,q2),(c2,0)], color = 'magenta', linestyle= '--') \
+ text("$c_2$", (c2, -0.005)) + text("$ q = -\\frac{F}{S_2}(c-c_1)+q_0$", (0.045, 0.05), color = 'magenta', fontsize = "large")
show(gr_datos+gr_Langm+gr_etapa1+gr_etapa2)
html('<h3>Parte d) Dos etapas a flujo cruzado, calcular sólido mínimo</h3>')
S1m = L*(c0-c_A)/(qA_L(c_A) + q0)
S2m = L*(c_A-c2)/(qA_L(c_A=c2) + q0)
STm = S1m+S2m
S_Tm, c1m = find_local_minimum(STm, c2, c0)
q1m = qA_L(c1m)
show (r"$S_{T}$ /kg $=$", STm)
show (r"$S_{T, mín}= %.3g$ kg; $c_{1}= %.3g$ kg/L" %(S_Tm, c1m))
show (r"$Ahorro = %s $ kg" %(numerical_approx(((S1+S2)-S_Tm), digits=3)))
show (r"$S_{1}= %s$ kg; $S_{2}= %s$ kg" %(numerical_approx(S1m(c1m), digits=3), numerical_approx(S2m(c1m), digits=3)))
html('<h3>Parte e) Una etapa con total obtenido en d)</h3>')
c1e, q1e = Calcula_etapa(W_L=L, W_S=S_Tm, c_entra=c0, q_entra=q0, q_isot=qA_L)
show (r'$c_1 = %.3g$ kg/L; $q_1 = %.3g$ kg/kg' %(c1e, q1e))
gr_etapa1e = line([(c0,q0),(c1e,q1e)], color = 'green', thickness=2, legend_label = 'Una sola etapa %.3g kg'%S_Tm) + line([(c1e,q1e),(c1e,0)], color = 'green', linestyle = '--')
gr_etapa2m = line([(c0,q0),(c1m,q1m)], color = 'purple') + line([(c1m,q1m),(c1m,0)], color = 'purple', linestyle= '--') \
+ line([(c1m,q0),(c2,q2)], color = 'purple', legend_label = 'Dos etapas %.3g kg en total'%S_Tm) + line([(c2,q2),(c2,0)], color = 'purple', linestyle= '--')
show(gr_datos+gr_Langm+gr_etapa1e+gr_etapa2m)