The program looks for the minimun of the function within the search space, for every funcion, the intial data may change. To look for the maximun of the function, you need to change the sign of the function only on the testefunction.
Orlando Ramirez Barron (2020). Particle swarm optimization for 2 dimentional functions (https://www.mathworks.com/matlabcentral/fileexchange/59993-particle-swarm-optimization-for-2-dimentional-functions), MATLAB Central File Exchange. Retrieved .