Reputation: 45
I use MATLAB optimization toolbox function fminunc
to optimize two parameters with different lengths based on my objective function. I need to optimize both parameters. The algorithm needs to start with an initial points for these parameters:
x0 = randn(10,3);
y0 = rand(20,1);
options = optimoptions(@fminunc,'Algorithm','quasi-newton');
[Coeff_min, Error_min] = fminunc(@objectiveFunction, x0, options)
How can I pass both initial parameters to the function?
Upvotes: 2
Views: 492
Reputation: 114786
What you can do is fool matlab to think you only have one parameter of numel
10*3 + 20:
function v = objective_wrapper( xy )
x = reshape(xy(1:30),10,3);
y = reshape(xy(31:end),20,1);
v = objectiveFunction(x,y);
Now you can optimize:
xy0 = [x0(:);y0(:)];
[Coeff_min, Error_min] = fminunc(@objective_wrapper, xy0, options);
Upvotes: 3