Maxima has a feature which makes this sort of calculation especially easy.
You define the fixed elements using assignment
M[1] : ...
and the parameterized ones using functional definition
M[i] := ...
In your case:
M[1] : matrix([cos(a),(- %i/n1)*sin(a)],[(-%i*n1)*sin(a),cos(a)]) $
M[2] : matrix([cos(b),(- %i/n2)*sin(b)],[(-%i*n2)*sin(b), cos(b)]) $
M[i] := if i<1 then 0 else M[i-1].M[i-2] $
Once a given M[i] is calculated, it is saved and not recalculated, so if yo
u
change the definitions, you must erase (kill) the results.
The elements get very large. The trick in getting a useful result will be
simplifying in a useful way.
-s