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

Rakesh Kumar

 

07 Dec 2005 (Updated )

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

nonSmoothFcn(x)
function f = nonSmoothFcn(x)
%NONSMOOTHFCN is a non-smooth objective function.

% This is a vectorized function which will find the function value at all
% points 'x'. 'x' can be a vector or can be matrix.
for i = 1:size(x,1)
    if x(i,1) < -3
         temp = 0.5*x(i,1)^2 + 10 + abs(x(i,2));
        f(i) = temp +  abs(x(i,2)) - dejong3fcn(x(i,:))+ patho(x(i,:));
    elseif x(i,1) <= 0
        temp = -2*sin(x(i,1)) - (x(i,1)*x(i,2)^2)/10 + 15;
        f(i) = 0.5*x(i,1)^2 + temp + abs(x(i,2));
    elseif x(i,1) > 0
        f(i) = -2*sin(x(i,1)) - (x(i,1)^2*log(x(i,2)))/10 + 15 ...
            + .3*sqrt(x(i,1)) - abs(x(i,2)) - dejong3fcn(x(i,:));
    end
end

function fval = patho(x)
% Helper function to nonSmoothFcn.
% http://mathworld.wolfram.com
Max = 500;
fval = zeros(size(x,1),1);
for k = 1:Max
   arg = sin(pi*k^2*x)/(pi*k^2);
   fval = fval + sum(arg,2);
end

function fval = dejong3fcn(x)
% Helper function to nonSmoothFcn.
% http://mathworld.wolfram.com
fval = zeros(size(x,1),1);
for i = 1:size(x,1)
    p = x(i,:);
    p = max(-2.048,min(2.048,p));
    if((any(p < -6)) || (any(p > 6)))
        fval(i) = 1000;
    else
        fval(i) = sum(floor(p));
    end
end

Contact us