so, basically, I have the amount of NaOH that has to be added (at least in theory)
    print 'diff TA =', diff_TA*1e6
    # (Bag values) Carbonate Bag:
    #H_CO3 = 10.0**(-pH_target)
    #OH_CO3 = KWF/H_CO3
    #CAlk_CO3 = DIC_CO3*K1F*(H_CO3 + 2.0*K2F)/(H_CO3*H_CO3 + K1F*H_CO3 + K1F*K2F)
    #TA_CO3 = CAlk_CO3 + OH_CO3 - H_CO3
    #0 = DIC_CO3*K1F*(H_CO3 + 2.0*K2F)/(H_CO3*H_CO3 + K1F*H_CO3 + K1F*K2F) + KWF/H_CO3 - H_CO3 -
TA_CO3
    # the equation differs if you use NaHCO3 because the charge balance is slightly different:
    def H_func_CO3bag(H):
    val = (TA_CO3 - (DIC_CO3*K1F*(H + 2.0*K2F)/(H*H + K1F*H + K1F*K2F) + KWF/H - H))**2.0
    #print val
    return val
    # take a good guess from the approximation
    H_init = 10**(-pH_chamber)
    H_opt = opt.fmin(H_func_CO3bag, H_init, xtol = 1e−12, ftol = 1e−12, maxiter=None, maxfun=None, full_output=0,
disp=1, retall=0, callback=None)
    print 'print target H for the NaHCO3 bag:'
    print 'H for NaHCO3=', H_opt
    pH_CO3_opt=-np.log10(H_opt)
    print 'print target pH for the NaHCO3 bag:'
    print 'the resulting pH of the NaHCO3 solution is', pH_CO3_opt
    # test if this pH results the correct TA
    CAlk_opt = DIC_CO3*K1F*(H_opt + 2.0*K2F)/(H_opt*H_opt + K1F*H_opt + K1F*K2F)
    OH_opt = KWF/H_opt
    TA_opt = CAlk_opt + OH_opt - H_opt
    print 'TA CO3', TA_CO3*1e6, 'minus TA opt', TA_opt*1e6, '=', (TA_CO3-TA_opt)*1e6
    #************************************************************************************************************
    # now titrate the NaHCO3 bag to the target pH
    # and the same for the other solution
    # (Bag values)
    pH_start = 7.968 #pH_NaHCO3_opt
    pH_target= pH_CO3_opt
    #amount of acid needed (first calculated without buffering capacity)
    mol_NaOH=10.0**(-pH_start)−10.0**(-pH_target)
    # I have to calculate the amount of protons that are consumed also by the buffering system of the carbonate chemistry,
and this on top of the pH change without the buffering capacity.
    H_start=10.0**(-pH_start)
    H_end=10.0**(-pH_target)
    OH_start=KWF/H_start
    OH_end=KWF/H_end
    CO3_start=DIC_CO3*K1F*K2F/(K1F*H_start + H_start*H_start + K1F*K2F)
    HCO3_start=DIC_CO3*K1F*H_start/(K1F*H_start + H_start*H_start + K1F*K2F)
    H2CO3_start=DIC_CO3-HCO3_start-CO3_start
    CO3_end=DIC_CO3*K1F*K2F/(K1F*H_end + H_end*H_end + K1F*K2F)
    HCO3_end=DIC_CO3*K1F*H_end/(K1F*H_end + H_end*H_end + K1F*K2F)
    H2CO3_end=DIC_CO3-HCO3_end-CO3_end
    print 'CO3 from:', CO3_start*1e6, 'to', CO3_end*1e6, '\mu mol'
    print 'HCO3 from:', HCO3_start*1e6, 'to', HCO3_end*1e6, '\mu mol'
    print 'H2CO3 from:', H2CO3_start*1e6, 'to', H2CO3_end*1e6, '\mu mol'
    H_diff=(2*H2CO3_start+HCO3_start+H_start-OH_start)-(2*H2CO3_end+HCO3_end+H_end-OH_end)
    print 'mol NaOH needed to adjust pH_NaHCO3 from', pH_start, 'to', pH_target, 'is:', H_diff, 'compared to:',
mol_NaOH, 'without considering the buffer capacity'
```
print 'at a molarity of ', mol\_base, 'this requires ', H\_diff/mol\_base\*1e3\*5.0, 'ml of base for 5 L solution' #\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
