我需要尽量减少以下功能MATLAB - 写入目标函数fmincon()
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.
这个问题显然是在我的目标函数中,但尽管尝试了几次,但我仍然无法正确写入它。我在这里看到了一些解决方案,但即使我的“闭包函数”只接受一个参数并且调用另一个参数,它的格式仍然不正确。
请问您能帮我解决吗?