1) the code is exactly in your link, I did not change it at all,
2) I understand the x*x = 1, constraint; it must hold.
3) this formula A*x./x = lambda *I (1 vector), I did not add, I just tested the result and see what it will be
because this example is to find the eigenvector. Since it is an eigenvector, it must hold A*x = lamda*x, it is the definition.
so I want to see if the result of x by PSO solver in the code can give a valid result, which means if A*x./x = lambda (1 vector),
it turns out it is not, but this means this x is not the correct solution.
or it means the cost function is not very correct, at least it should have another constraint,
I attached two figures by PSO and trustregions, respectively,
and for each, variable x is the output, and we know the input A, so I use it to test this equation A*x./x
trustregions gives Reiman gradient close to 0, and lambda equal to one constant,
but PSO failed to give these results,
That makes me to ask, PSO can not give a valid result to this problem (because the constraints is not enough just by giving xx=1),