www.gusucode.com > globaloptim 案例源码程序 matlab代码 > globaloptim/showSmoothFcn.m
function showSmoothFcn(fcn,range) %showSmoothFcn plot a fitness function in two dimensions % plotObjective(fcn,range) where range is a 2 by 2 matrix in which each % row holds the min and max values to range over in that dimension. % Copyright 2005-2011 The MathWorks, Inc. pts = 100; span = diff(range')/(pts - 1); x = range(1,1): span(1) : range(1,2); y = range(2,1): span(2) : range(2,2); pop = zeros(pts * pts,2); k = 1; for i = 1:pts for j = 1:pts pop(k,:) = [x(i),y(j)]; k = k + 1; end end values = feval(fcn,pop); values = reshape(values,pts,pts); clf; surf(x,y,values) shading interp light lighting phong hold on rotate3d on view(37,60) set(gcf,'Renderer','opengl'); rotate3d off