finished LMS.m