Dear Mukund
Let there be two capacitors Ca and Cb which are charged to different potentials.Let Ca be at a potential Va and Cb be at a potential Vb.
Common potential of the two capacitors, Vc = ( CaVa + CbVb )/ ( Ca + Cb )
Energy that can be obtained from capacitor Ca= CaVa2/2
Energy that can be obtained from capacitor Cb = CbVb2/2
Total Energy that can be obtained from both Ca and Cb before sharing of charges takes place = CaVa2/2 + CbVb2/2
Energy that can be obtained from both the capacitors after sharing of charges has taken place = ( Ca + Cb ) Vc2/2
Thus , Loss of Energy during sharing of charges = Total Energy that can be obtained from both the capacitors before sharing of charges has taken place - Energy that can be obtained after sharing of charges has occured
Energy Loss = ( CaVa2/2 + CbVb2/2 ) - (Ca+Cb)Vc2/2
= (CaVa2/2 + CbVb2/2 ) - [( Ca + Cb )( CaVa + CbVb )2/2(Ca+Cb)2] ......(1)
Solving equation 1 , we get :-
Energy Loss = CaCb ( Va - Vb )2/2(Ca+Cb). This much amount of energy is always lost when two capacitors charged to different potentials share their charges.