How to Linearise an Input Image before applying Color Correction?
Your linearization gamma calculation does not take into account the correction matrix.

You could do a combined numerical optimization of the pre-correction-matrix gamma adjustment, the correction matrix, and the post-correction-matrix gamma adjustment, preferably using a colorimetric error metric. There are 11 variables to optimize (or up to 14 if you wand to add constant terms). That's doable without too much work if you don't need to repeat this very often. I have a C++ Differential Evolution optimization library here that should be able to handle it: http://yehar.com/blog/?p=643