Code covered by the BSD License  

Highlights from
New Approaches to Constrained Optimization in MATLAB

image thumbnail

New Approaches to Constrained Optimization in MATLAB

by

 

07 Dec 2005 (Updated )

M-files accompanying the webinar held on November 05, 2005

showNonSmoothFcn(fcn,range)
function showNonSmoothFcn(fcn,range)
% Function to plot objective function 'fcn' in the range 'range'.

% If no input arguments, use default
if(nargin == 0)
    fcn = @rastriginsfcn;
    range = [-5,5;-5,5];
end

pts = 25;
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

% Objective function must be vectorized; saves a lot of time!
values = feval(fcn,pop);
values = reshape(values,pts,pts);

surf(x,y,values)
shading interp
light
lighting phong
hold on
contour(x,y,values)
rotate3d
view(37,60)


Contact us