Converted from Scilab to Matlab

There are some issues remaining.