【发布时间】:2016-11-21 16:26:57
【问题描述】:
我需要最小化以下功能
nDOF、nprocs 和 T 取自该表的前两列
所以我在 MATLAB 中有以下向量
nDOF =
3993
3993
3993
3993
3993
3993
3993
3993
7623
7623
7623
7623
7623
7623
7623
7623
nprocs =
1
2
3
4
6
8
12
24
1
2
3
4
6
8
12
24
vals =
0.6564
0.2569
0.2719
0.1743
0.1305
0.1230
0.1739
0.1147
1.1998
0.5088
0.6419
0.2899
0.2192
0.2033
0.2126
0.1821
我想用函数fmincon 最小化函数$F$,如下所示:
fmincon(@(theta) objFunctionMatAssemble(theta(1), theta(2), theta(3), theta(4), ndofIN, nprocsIN, vals), [0 0 0 0]', [], [], [], [], [0 0 0 0], [+inf +inf +inf +inf] )
objFunctionMatAssemble 的代码:
function [t] = objFunctionMatAssemble(alpha, beta, gamma, delta, ndofIN, nprocsIN, vals)
t = 0;
for i=1:length(nprocsIN)
t = t + alpha*ndofIN^beta + gamma*((ndofIN(i)^delta)/nprocsIN(i) - vals(i))^2;
end
end
问题是,我收到以下错误:
>> fmincon(@(theta) objFunctionMatAssemble(theta(1), theta(2), theta(3), theta(4), ndofIN, nprocsIN, vals), [0 0 0 0]', [], [], [], [], [0 0 0 0], [+inf +inf +inf +inf] )
Error using ^
Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead.
Error in objFunctionMatAssemble (line 4)
t = t + alpha*ndofIN^beta + gamma*((ndofIN(i)^delta)/nprocsIN(i) - vals(i))^2;
Error in @(theta)objFunctionMatAssemble(theta(1),theta(2),theta(3),theta(4),ndofIN,nprocsIN,vals)
Error in fmincon (line 535)
initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.
问题显然出在我的目标函数中,但尽管尝试了几次,我仍无法正确编写它。我在这里看到了一些关于 SO 的解决方案,但是即使我的“闭包函数”只接受一个参数并调用另一个参数,它的格式仍然不正确。
你能帮我解决这个问题吗?
【问题讨论】:
标签: matlab nonlinear-optimization non-linear-regression