我需要儘量減少以下功能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.
這個問題顯然是在我的目標函數中,但儘管嘗試了幾次,但我仍然無法正確寫入它。我在這裏看到了一些解決方案,但即使我的「閉包函數」只接受一個參數並且調用另一個參數,它的格式仍然不正確。
請問您能幫我解決嗎?