def create_P(self): equations_for_P = Eq(Sum(P[k] * _omega[k], (k, 1, self.N)), Sum(p[k] * _v[k], (k, 1, self.N))) if self.debug: debug_display(equations_for_P) # subs omega_i and v_i sub_equations_for_P = TatarinovSystem.sub_Eqs( equations_for_P.doit(), # important self.omega_equations + self.v_equations) # for Ex: omega[1] -> nu1), v[1] -> x', .... # subs_constraints sub_conn_equations_for_P = self.sub_constraints(sub_equations_for_P) if self.debug: debug_display(sub_conn_equations_for_P) # to equate the coefficients left_coeffs = poly( sub_conn_equations_for_P.args[0], TatarinovSystem.right_part_Eqs(self.omega_equations)).coeffs() right_coeffs = poly( sub_conn_equations_for_P.args[1], TatarinovSystem.right_part_Eqs(self.omega_equations)).coeffs() final_equations_for_P = [ Eq(left, right) for left, right in zip(left_coeffs, right_coeffs) ] self.P = final_equations_for_P
subs = {} eqs = [] # rate of x rate_expr = k_f*Y*(Z-x) - k_b*x rate_eq = Eq(Derivative(x,t), rate_expr) eqs.append(rate_eq) integrand = 1/rate_expr inte_eq_lhs = Integral(integrand.subs({x: chi}), (chi,0,x)) inte_eq_rhs = Integral(1, (tau,0,t)) inte_eq = Eq(inte_eq_lhs, inte_eq_rhs) eqs.append(inte_eq) expl_in_x_eq = inte_eq.doit().simplify() eqs.append(expl_in_x_eq) expl_in_t_eq = Eq(x, solve(expl_in_x_eq, x)[0]) eqs.append(expl_in_t_eq) alt_expl_in_t = Z*k_f*Y/(k_f*Y+k_b)*(1-exp(-t*(k_f*Y+k_b))) assert (expl_in_t_eq.rhs - alt_expl_in_t).simplify() == 0 alt_expl_in_t_eq = Eq(x, alt_expl_in_t) eqs.append(alt_expl_in_t_eq) def main(): # GENERATES WITHOUT ARGUMENTS: rev_unary_1.tex rev_unary_rate.tex rev_unary_k_b.c rev_unary_K_eq.c from sympy.printing.latex import latex
eqs = [] # rate of x rate_expr = k_f * (Y - x) * (Z - x) rate_eq = Eq(Derivative(x, t), rate_expr) eqs.append(rate_eq) integrand = k_f / rate_expr inte_eq_lhs = Integral(integrand.subs({x: chi}), (chi, 0, x)) inte_eq_rhs = Integral(k_f, (tau, 0, t)) inte_eq = Eq(inte_eq_lhs, inte_eq_rhs) eqs.append(inte_eq) expl_in_x_eq = inte_eq.doit(manual=True).simplify() eqs.append(expl_in_x_eq) expl_in_t_eq = Eq(x, solve(expl_in_x_eq, x)[0]) alt_expl_in_t = Y * (1 - exp(k_f * t * (Z - Y))) / (Y / Z - exp(k_f * t * (Z - Y))) assert (alt_expl_in_t - expl_in_t_eq.rhs).simplify() == 0 alt_expl_in_t_eq = Eq(x, alt_expl_in_t) eqs.append(alt_expl_in_t_eq) def main(): # GENERATES WITHOUT ARGUMENTS: irrev_binary_1.tex irrev_binary_2.tex irrev_binary_rate.tex irrev_binary_k_b.c irrev_binary_K_eq.c from sympy.printing.latex import latex open("irrev_binary_1.tex", "wt").write(as_align_env(eqs[:2]))
subs = {} eqs = [] # rate of x rate_expr = k_f * Y * (Z - x) - k_b * x rate_eq = Eq(Derivative(x, t), rate_expr) eqs.append(rate_eq) integrand = 1 / rate_expr inte_eq_lhs = Integral(integrand.subs({x: chi}), (chi, 0, x)) inte_eq_rhs = Integral(1, (tau, 0, t)) inte_eq = Eq(inte_eq_lhs, inte_eq_rhs) eqs.append(inte_eq) expl_in_x_eq = inte_eq.doit().simplify() eqs.append(expl_in_x_eq) expl_in_t_eq = Eq(x, solve(expl_in_x_eq, x)[0]) eqs.append(expl_in_t_eq) alt_expl_in_t = Z * k_f * Y / (k_f * Y + k_b) * (1 - exp(-t * (k_f * Y + k_b))) assert (expl_in_t_eq.rhs - alt_expl_in_t).simplify() == 0 alt_expl_in_t_eq = Eq(x, alt_expl_in_t) eqs.append(alt_expl_in_t_eq) def main(): # GENERATES WITHOUT ARGUMENTS: rev_unary_1.tex rev_unary_rate.tex rev_unary_k_b.c rev_unary_K_eq.c from sympy.printing.latex import latex
eqs = [] # rate of x rate_expr = k_f * (Y - x) * (Z - x) rate_eq = Eq(Derivative(x, t), rate_expr) eqs.append(rate_eq) integrand = k_f / rate_expr inte_eq_lhs = Integral(integrand.subs({x: chi}), (chi, 0, x)) inte_eq_rhs = Integral(k_f, (tau, 0, t)) inte_eq = Eq(inte_eq_lhs, inte_eq_rhs) eqs.append(inte_eq) expl_in_x_eq = inte_eq.doit(manual=True).simplify() eqs.append(expl_in_x_eq) expl_in_t_eq = Eq(x, solve(expl_in_x_eq, x)[0]) alt_expl_in_t = Y * (1 - exp(k_f * t * (Z - Y))) / (Y / Z - exp(k_f * t * (Z - Y))) assert (alt_expl_in_t - expl_in_t_eq.rhs).simplify() == 0 alt_expl_in_t_eq = Eq(x, alt_expl_in_t) eqs.append(alt_expl_in_t_eq) def main(): # GENERATES WITHOUT ARGUMENTS: irrev_binary_1.tex irrev_binary_2.tex irrev_binary_rate.tex irrev_binary_k_b.c irrev_binary_K_eq.c from sympy.printing.latex import latex open('irrev_binary_1.tex', 'wt').write(as_align_env(eqs[:2]))