Error in fmincon while I have the optimization toolbox

10 visualizaciones (últimos 30 días)
ikarry
ikarry el 20 de Feb. de 2023
Comentada: Torsten el 20 de Feb. de 2023
I just registered a trial version and activated it today. When I use the "ver" command, I can see the "optimization toolbox" installed. However, I am unable to run the following code:
% Define the objective function
fun = @(x) (x(1) - 1)^2 + (x(2) - 2.5)^2;
% Set the initial point and bounds
x0 = [0,0]; lb = [-1,-1]; ub = [3,3];
% Run the optimizer
options = optimoptions('fmincon','Display','iter');
[x,fval] = fmincon(fun,x0,[],[],[],[],lb,ub,[],options);
First-order Norm of Iter F-count f(x) Feasibility optimality step 0 3 7.250000e+00 0.000e+00 4.737e+00 1 6 3.099821e-01 0.000e+00 1.233e+00 3.245e+00 2 9 3.834104e-02 0.000e+00 3.409e-01 4.717e-01 3 13 5.861712e-03 0.000e+00 8.791e-02 2.724e-01 4 16 4.625011e-04 0.000e+00 2.511e-02 5.751e-02 5 19 9.023748e-07 0.000e+00 1.162e-03 2.071e-02 6 22 3.015896e-08 0.000e+00 2.012e-04 8.248e-04 7 25 4.599019e-12 0.000e+00 4.304e-06 1.740e-04 8 28 2.995153e-12 0.000e+00 2.000e-06 2.819e-06 9 31 1.071919e-15 0.000e+00 2.001e-08 1.700e-06 Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
% Display the results
disp(x); disp(fval);
1.0000 2.5000 1.0719e-15
The error message I receive is:
"Function or variable 'eml_option' is not recognized.
Error in optim.coder.validate.checkProducts
Error in fmincon
Error in bayes_al (line 11) [x,fval] = fmincon(fun,x0,[],[],[],[],lb,ub,[],options);"
Could you please help me with this issue?
  4 comentarios
ikarry
ikarry el 20 de Feb. de 2023
Very crazy, these codes were from ChatGPT, and I am trying my best to solve this problem, but failed and I am crazy
Torsten
Torsten el 20 de Feb. de 2023
You didn't anwer my question: Do you somewhere use a Function or variable 'eml_option' ?
As you can see above, your code works in R2022b, and I guess this is the same as your test version.
What if you use
% Define the objective function
fun = @(x) (x(1) - 1)^2 + (x(2) - 2.5)^2;
% Set the initial point and bounds
x0 = [0,0]; lb = [-1,-1]; ub = [3,3];
[x,fval] = fmincon(fun,x0,[],[],[],[],lb,ub);
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
% Display the results
disp(x); disp(fval);
1.0000 2.5000 1.0719e-15

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Surrogate Optimization en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by