MATLAB code for physics course