Reputation: 11
This question arises from a matlab community add-on function "general simulated annealing algorithm". The function needs a 'loss function' which is required to be minimized. The loss function is a function handle, for example the camel function camel = @(x,y)(4-2.1*x.^2+x.^4/3).*x.^2+x.*y+4*(y.^2-1).*y.^2
, then the loss function is expressed as loss = @(p)camel(p(1),p(2))
.
Now, what I want to minimize is a matrix eigenvalue function, say goal=@(x,y)sum(abs(sort(real(eig([x,y;y,x])))-sort(real(eig(A)))))
where A is a given matrix. But generally the matrix [x,y;y,x]
in the goal
is replaced by a much larger matrix H
. For example, there 30 independent variables forming a vector x
, and I have an algorithm to construct a 16x16 matrix using these variables, say for i=1:16;H(2*i-1:2*i,2*i-1:2*i)=[x(1),x(2);x(3),x(4)];end
.
So it's quite inconvenient to directly write it down and insert it into the eqution. What I expect is a way to retain the construction of H
in the function handle, so maybe I need something like nested function?
Upvotes: 0
Views: 99