Matlab Code For Simple Algorithm