Converted Octave syntax so code runs on Matlab.
FIX: Logic broke converting do..until -> while..
Try values for D, E and S suggested by Ian.
Duh! Using the right numbers would help.