Azzera filtri
Azzera filtri

Global optimization - data type error

2 visualizzazioni (ultimi 30 giorni)
Jen W
Jen W il 4 Gen 2021
Commentato: Jen W il 5 Gen 2021
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)

Risposta accettata

Matt J
Matt J il 4 Gen 2021
Modificato: Matt J il 4 Gen 2021
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 Commenti
Walter Roberson
Walter Roberson il 4 Gen 2021
I have now filed a bug report about the order being documented as "alphabetical".
Jen W
Jen W il 5 Gen 2021
Thanks Matt and Walter.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by