def main(tdelay=1.0, B0=0.6, noiselvl=3e-4, nt=200, eps_l=4200.0, plot=False): """ Solution: 1. non-linear fit to: A) if approx equal conc A+A -> C B) else: A+B -> C 2. Use as guess for guess and shoot. A + B <-> C """ Keq = 10.0 k_fw_true = 1.3 ktrue = [1.3, k_fw_true/Keq] c0 = [1.0, B0, 0.0] ttrue = np.linspace(0, 10, nt) rd_eq = ReactionDiffusion(3, [[0, 1], [2]], [[2], [0, 1]], k=ktrue) tinp, yinp = simulate_stopped_flow( rd_eq, ttrue, c0, ktrue, noiselvl, eps_l, tdelay) k_fw_opt, d_opt, eps_l_opt = fit_binary_eq_from_temporal_abs_data( tinp, yinp, c0, Keq, True) rd_eq.k = [k_fw_opt, k_fw_opt/Keq] integr = run(rd_eq, c0, ttrue) yopt = integr.Cout[:, 0, 2]*eps_l_opt if plot: import matplotlib.pyplot as plt # Plot plt.subplot(2, 1, 1) plt.plot(tinp, yinp, label='Input data') plt.plot(ttrue-tdelay, yopt, label='Shooting Opt (k={})'.format(k_fw_opt)) plt.legend(loc='best') plt.subplot(2, 1, 2) plt.plot(tinp, yinp, label='Input data') # TODO: this needs to be improved... yquad = (B0-1/(1/B0+k_fw_opt*ttrue))*eps_l_opt plt.plot(ttrue-tdelay, yquad, label='Equal initial conc treatment') plt.legend(loc='best') plt.show()