first pass at porting matrix code from PBASIC