rand('state',333); imax = 300; n = 60; tol=1e-14; current = 2*rand(n,4) - 1; children = zeros(n,4); vals = zeros(n,1); for j=1:n vals(j) = maxerror(current(j,:)); end oldbest = min(vals); for i=1:imax for j=1:n select = ceil(n*rand(3,1)); children(j,:) = [1 0.4 -0.4]*current(select,:); end for j=1:n childval = maxerror(children(j,:)); if childval < vals(j) current(j,:) = children(j,:); vals(j) = childval; end end if mod(i,10)==0 best = min(vals); if (abs(best-oldbest) < tol), break; end oldbest = best; end end sol = min(vals)