How to Add Matrix as x0 Variable in fminsearch?

173 Views Asked by At

I am using fminsearch to minimize objective function. This requires defining variable x0 (usually vector) as estimates of solution which algorithm uses as starting point of finding solution. However, I want to create many estimates and evaluate objective function for each of these estimates. I tried to define x0 as matrix of estimates, but I didn't get result I wanted.

1

There are 1 best solutions below

0
Arc On

Suppose each start parameter vector is stored in a row of x0, and fun is the function you want to minimize:

fun = @(x)100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
x0 = [-1.2, 1; -1.3, 2; 7 3.3];
for i = 1:size(x0,1)
    x(i,:) = fminsearch(fun,x0(i,:))
endfor

final output:

x =

   1.00000   1.00001
   1.00000   0.99999
   0.99997   0.99995