simulation matlab code