Global optimization - data type error
2 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I am trying to minimize the objective below using global optimization. The error I received is: "Error using fmincon. FMINCON requires all values returned by functions to be of data type double. Caused by: Failure in initial call to fmincon with user-supplied problem structure." I don't know how to fix this error. Any idea will be appreciated. Thanks in advance!
syms Cm Cc Cv Co
Cf = 1 - Cc - Cm - Cv - Co;
G = Cm*log(Cm) + Cc*log(Cc) + Cv*log(Cv) + Co*log(Co);
% Calculate the derivative of G w.r.t. the four variables
sym_mu_c = diff(G, Cc);
sym_mu_m = diff(G, Cm);
sym_mu_v = diff(G, Cv);
sym_mu_o = diff(G, Co);
% This function is to be minimized
sym_dis = vpa((sym_mu_c.^2 + sym_mu_m.^2 + sym_mu_v.^2 + sym_mu_o.^2).^0.5);
% Convert syms function to matlab function
mu_dis = matlabFunction(sym_dis);
% Bounds of the four variables
lowb = [0;0;0;0];
uppb = [1;1;1;1];
% Objective
obj = @(x)mu_dis;
% Define problem
gs = GlobalSearch;
opts = optimoptions(@fmincon, 'Algorithm', 'interior-point', 'MaxFunctionEvaluations', 1e6, 'MaxIterations', 1e6);
init = [0.204; 0.075; 1e-2; 1e-2];
prob = createOptimProblem('fmincon', 'x0', init, 'objective', obj, 'lb', lowb, 'ub', uppb, 'options', opts);
[x, fval] = run(gs, prob)
0 件のコメント
採用された回答
Matt J
2021 年 1 月 4 日
編集済み: Matt J
2021 年 1 月 4 日
mu_dis = matlabFunction( sym_mu_c.^2 + sym_mu_m.^2 + sym_mu_v.^2 + sym_mu_o.^2 );
obj=@(x) mu_dis( x(1), x(2), x(3), x(4) )
8 件のコメント
Walter Roberson
2021 年 1 月 4 日
I have now filed a bug report about the order being documented as "alphabetical".
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!