Dear Sam,
First of all I apologize for my strong word to you. I am very sorry. Yes your coding is very useful to me. Before you write I have already taken the ConstrBoundaryas soft instead of penalize and became successful. Thank you very much.

Dear sir,
I have a problem with 16 variables, out of which 9 variables are in decimals with range 0 to 1 and the rest are integers with range 1 to 4. Can I use your codings of pso?

Hallo sam
It is very sad that you have not replied my query till yet.Again I am facing another problem with your code which I am explaining.
I am getting the fitness function from a simulink file. The simulink file will run if the variables lie within lower bound and upper bound.But with your code sometimes the variables exceed the lower bound or upper bound so that the simulink file is not able to execute and it shows error.So please help me as soon as possible. Thanks.

Halo Sham,
I have to optimize 16 parameters. Out of which the first nine parameters are in the range of zero to one but the rest seven variables are in the range of one to four (only integers).So please help me to use your codings. Is your coding is useful for mixed integer constraints?Again is it useful for 16 variables?
Anticipating a quick reply.Thanking you.

Dear Sam,
Thanks for powerful pso toolbox. I have an error after running the code with nonlinear constraint. The error message is:
" Problem is infeasible due to nonlinear constraints"
I have checked that my nonlinear constraints is passed with my initial population that I supplied. What could be the possible place that I can take a look to fix this problem.
Thanks
Parinya

Thanks for pointing that out, Aman.
b should really be a column vector [2;1] so that it will fit the equation
[1 0 ; 0 1]*[x1; x2] ≤ [2; 1]
however it looks like GA is robust enough to check for and correct that error.
I will add a small piece of input-checking code in the next release so that PSO will yield the same behavior as GA.

Sam,If PSO toolbox syntax same as GA toolbox so then I have found one a little bugs(but not with GA If using same syanx )for example: If I compare n run both GA n PSO syntax for two variable objective function.... pso(@(x)(x(1)^2+x(2)^2+x(1)),2,[1 0;0 1],[2 1]) showing "hozcat " and "psocheckinitialpopulation" error
...BUT ga(@(x)(x(1)^2+x(2)^2+x(1)),2,[1 0;0 1],[2 1]) result come out

Comment only