code written in mgl and matlab