Watch this Author's files
Good, except for some small bug in the code. the miss use of function "sum" makes the program not stable. You mentioned it is not stable for large number. It is caused by this.
Contact us at files@mathworks.com