Question: How to rearrange formula(as matrix entries) to combinations of multivariables?

Like for instance if I have a formula: ((x^2+y^3)*a1+(x+y^3)*a2)/x^2 and other similar forms as entries for a matrix M, I want to change each entries to a form like this: ((x^2+y^3)/x^2)*a1 + ((x+y^3)/x^2)*a2, what would be the right way to do this?

Thanks for any answers in advance!

Please Wait...