Two bodies with masses m and M are attached to each other through a frictionless pulley. What are the forces acting on the bodies and what are the motion equations of the bodies?

By Newton's second law, for every body with mass m moving with acceleration a the product ma equals the resultant of all the forces acting on it. For the two bodies we get, accordingly:
     Ma1 = Mg - T
     ma2 = mg - T
Since the two bodies are tied together, but move in opposite directions, we can write a third equation:
     a1 = - a2
Denote: a1 = a , and substitute into the first two equations:
     Ma = Mg - T
     ma = T - mg
Add the two equations and get:
     a (m + M) = g (M - m)
Solve for a :
     a = g( M - m)/(M + m)
Solve the first equation for T :
     T = M (g - a)
Substitute the a we found, and get:
     T = 2mM/(M + m)
Initial Values of Parameters
Mass of left body (k) 4 kg
Mass of right body (k) 7 kg
Gravitational constant (g) 10 m/sec2