Optimization problem not finding the actual optimal value

10 views (last 30 days)
Hello!
I am trying to solve an optimization problem in the Problem-Based mode and I am having problems finding the local optimum. The function I am looking to optimize is located in a .m file developed by me, in which a single output Y value is calculated, which depends on the simulation and run of a computational model of my own. I am defining the objective of my problem with fcn2optimexpr and the optimization method I am using is fmincon. No matter what initial value X (a single variable) I assign to the problem, the program always tells me that it has already found the local optimum at the initial point assigned to X, without further iterations. I have already tried to modify the program tolerances (step size, objetive and contraint) and it keeps throwing the same result. Also, I tried changing the searching algoritm and nothing has worked out. Any idea what I can be doing wrong? Thank you very much. Below is the code used to define the problem and the text obtained in response.
prob = optimproblem("Description", "Optimization SUDS", "ObjectiveSense", "maximize");
x = optimvar('x');
x.LowerBound = 0;
x.UpperBound = 1;
obj = fcn2optimexpr(@opti, x);
prob.Objective = obj;
initialGuess.x = 0.1;
options = optimoptions("fmincon","Display","iter", "PlotFcn",["optimplotx",...
"optimplotfval","optimplotstepsize"]);
[sol, fval, exitflag, output] = solve(prob, initialGuess, "Options",options);
Initial Point is a local minimum that satisfies the constraints.
Optimizacion completed because at the initial point, the objetive function is non-decreasing in feasible directions to within the value of the optimality tolerance, and contraints are satisfied to within the value of the contraint tolerance
  2 Comments
Torsten
Torsten on 14 Mar 2022
What do you get back if you call your objective with the initial guess for x ?
Pascual Ferrans Ramírez
Pascual Ferrans Ramírez on 15 Mar 2022
Hi Torsten, thank you for your message. i get the actual value that Im looking for, 7.5

Sign in to comment.

Accepted Answer

Matt J
Matt J on 14 Mar 2022
Edited: Matt J on 14 Mar 2022
Making sure you don't have any round(), ceil(), floor() or other discretization operations in your simulation code. Also, make sure you have read the guidelines on optimizing a simulation here,
Finally, since your problem only has a single unknown, I would use fminbnd().
  3 Comments
Pascual Ferrans Ramírez
Pascual Ferrans Ramírez on 15 Mar 2022
Thank you both for your messages. That is exactly what was happening. fminbnd() is working fine. Thanks.
Matt J
Matt J on 15 Mar 2022
Glad it's working, but then please Accept-click the answer to indicate so.

Sign in to comment.

More Answers (0)

Categories

Find more on Problem-Based Optimization Setup in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!