In equation (12), q should be a. Otherwise, equations (9) – (12) are correct for implementation purposes. Equation (6) should strictly be
to match equation (10) in the least squares approach.