我使用MATLAB优化工具箱函数fminunc
根据我的目标函数优化两个不同长度的参数。我需要优化这两个参数。算法需要从这些参数的初始点开始:
x0 = randn(10,3);
y0 = rand(20,1);
options = optimoptions(@fminunc,'Algorithm','quasi-newton');
[Coeff_min, Error_min] = fminunc(@objectiveFunction, x0, options)
如何将两个初始参数传递给函数?
答案 0 :(得分:2)
你可以做的是傻瓜matlab认为你只有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);
现在你可以优化:
xy0 = [x0(:);y0(:)];
[Coeff_min, Error_min] = fminunc(@objective_wrapper, xy0, options);