Global optimization - data type error

1 次查看(过去 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)

采纳的回答

Matt J
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
Walter Roberson 2021-1-4
I have now filed a bug report about the order being documented as "alphabetical".

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by