How to define the objective function to solve an optimization problem with Matlab?

4 views (last 30 days)
Dear all,
I have an optimization problem, but I don’t know how to define the minimization function properly and which optimization algorithm available in Maltab is the most appropriate.
I had previously used fminsearch to curve fitting a fractional derivative model to experimental data and it was OK. However, now I don’t have an analytical equation and so I don’t know how to define the minimization function of even if it is possible to use the Matlab Optimization toolbox for that.
I have the experimental vibration spectrum of hundreds of machines and their division by a pattern spectrum, which I would call Failure spectrum from now on. The aim of the optimization is to define a limit function that will lead to X % of defective machines. The limit is not constant in frequency, it is the following function:
Ylim, 1=< x <= xini
Ylim/ratio, xini< x <= xini+wide
Ylim, xini+wide< x <= 500
where the variables to be optimized are Ylim, ratio, xini and wide.
The code I have written does the following:
  1. Initialize the variables and obtain the limit function.
  2. Compare the first failure spectrum with the limit function, if the failure spectrum is bigger than the limit at any frequency count 1 and continue with the next failure spectrum.
  3. Calculate the error between the define defective by the user and the defective obtain with the actual limit function. This error is the minimized function.
I have first tried with frmincon to restrict the value of the variables, but the value of the variables is all the time the same and nothing is optimized. I have then tried with fminsearch and patternsearch and the same happened. There is no a “Matlab error” but nothing is optimized. I know little about optimization and I am not sure if am defining in a wrong way the minimization function or this problem cannot be solved in this way. I would deeply appreciate any help or clarification.
This is part of the code where the error is calculate ( 2 and 3 steps of the code):
[r,c]=size(Failure_spec_matrix);
cont=cell(1,c);
for i=1:c
Filure=Failure_spec_matrix(:,i);
location=find(Filure>Limit_spec');
count(1,i)={location};
end
count_total=find(~cellfun(@isempty,cont));
error=(length(count_total)*100/c)-defective_defined;
Thank you very much in advance!!

Accepted Answer

Alan Weiss
Alan Weiss on 20 Apr 2020
If I understand you correctly, your objective function (the thing you are trying to minimize) is integer-valued. Small changes in the control variables (the things you can move to change the objective function) don't change the value of the objective function.
If I understand correctly, you might try patternsearch with a large initial mesh size.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  3 Comments
Alan Weiss
Alan Weiss on 22 Apr 2020
If you have validated your objective function (seen that it gives correct values for various inputs), then the only other thing I can suggest is to try surrogateopt. This is a global solver that is time-consuming to run, but attempts to find a global minimum for small-dimensional problems like yours.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Lia
Lia on 23 Apr 2020
I have tried with surrogateopt as you suggested and it works fine. I deeply appreciate your help, thank you!
Lia

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!