Well, but one can combine various inputs from both legacy and segwit (p2sh, bech32) addresses into one transaction. Does anyone know how to calculate the transaction fee in this case? Is there any formula to do that? I have asked this question in Russian section and they pointed me to
https://coinb.in/#fees site that could help in estimation. Regardless, I would like to have the reliable mathematical formula to control the fee.
For controlling the fee, I guess, you don't need to know the mathematical formula. However, the formula is for calculation of transaction size, not for the fees. Fees can be found at your pointed web, you can pay less or more, it's your choice.