Javascript Port of Carl Edward Rasmussen's minimize.m