:

## Get help

hi all,

I  have a program written using Matlab, how can I change it into a program written using Maple.

the program:

% THE
% MATLAB

function [xmin, fxmin, iter] = PSO

%%%
success = 0;

PopSize = 20;
MaxIt = 5000;
iter = 0;

fevals = 0;
maxw = 1.2;

minw = 0.1;

weveryit = floor(0.75*MaxIt);
c1 = 0.5;
c2 = 0.5;
inertdec = (maxw-minw)/weveryit;
w = maxw;
f = “DeJong”;
dim = 2;

upbnd = 5;

wbnd = –5;
GM = 0;
ErrGoal = 1e–3;

% Initializing
popul = rand(dim, PopSize)*(upbnd-lwbnd) + lwbnd;
vel = rand(dim, PopSize);

%Evaluate
for i = 1:PopSize,
fpopul(i) = feval(f, popul(:,i));
fevals = fevals + 1;
end

% Initializing
% values
bestpos = popul;
fbestpos = fpopul;

% Finding
[fbestpart,g] = min(fpopul);
lastbpf = fbestpart;

% SWARM EVOLUTION LOOP ? START ?
while (success == 0) & (iter < MaxIt),
iter = iter + 1;
% Update the value of the inertia weight w
if (iter<=weveryit)
w = maxw – (iter–1)?inertdec;
end

% VELOCITY UPDATE
for i=1:PopSize,
A(:,i) = bestpos(:,g);
end
R1 = rand(dim, PopSize);
R2 = rand(dim, PopSize);
vel = w?vel + c1?R1.?(bestpos-popul) + c2?R2.?(A-popul);

%

popul = popul + vel;

% Evaluate the new swarm
for i = 1:PopSize,
fpopul(i) = feval(f,popul(:, i));
fevals = fevals + 1;
end

% Updating
changeColumns = fpopul < fbestpos;
fbestpos = fbestpos.*(~changeColumns) + fpopul.*changeColumns;
bestpos(:, find(changeColumns)) = popul(:, find(changeColumns));

% Updating
[fbestpart, g] = min(fbestpos);

% Checking
%if
if abs(fbestpart-GM) <= ErrGoal
success = 1;
else
lastbpf = fbestpart;
end
end
%  LOOP ? END ?
% Output
xmin = popul(:,g);
fxmin = fbestpos(g);

function DeJong=DeJong(x)
DeJong = sum(x.?2);

Thank you so much

Ahmed

﻿