Fix typo.
The math error Peter identified should now be fixed.  To keep the sizes of equations manageable, I now define the shorthand q(i,a) earlier.