general BAT algorithm for unconstrained optimization problem like sphere example code is available at http://www.mathworks.com/matlabcentral/fileexchange/37582-bat-algorithm--demo-
But the thing first u identify which type of problem that you want solve later study the BAT code given in above link