Changed
MTTY := MTTY + MTTEyx*MTTdX + MTTEyu*MTTdu;
to
MTTY := MTTY + MTTEyx*MTTEdX + MTTEyu*MTTdu;

This sorts out the problem when dz appears in the output equation.