resuming fminsearch from where it's left

3 views (last 30 days)
Gorkem
Gorkem on 5 Dec 2016
Commented: Alan Weiss on 5 Dec 2016
Hi everyone,
I am using fminsearch on simulink real-time system. It's called once in a while not peridoically but can say roughly every 1 s.
My real time sampling period is 1 ms. However, fminsearch takes about 2.5-3.5 ms causing system overload. That's not a problem for me because I don't need the optimizer result in the next 10 mseconds.
My problem is that there are some tasks that has to be executed every 1 ms. When overload occurs, this cannot be fulfilled for the next 3 iterations.
As a resolution, I was think of limiting the max number of function evaluations and max number of iterations to a value satisfying 1 ms execution period. Then, starting fminsearch from where it's left at the previous step. Currently, an optimization is completed in nearly 150 function evaluations.
However, I can't manage to change MaxFunEvals and MaxIter. By default, they are both set as '200*numberofvariables'. Matlab doesn't allow me to change MaxFunEvals or MaxIter to 50 (for example), It gives an error. So I tried '50*numberofvariables' but that doesn't limit the number of function evaluations to 50. What's the proper way of doing this?

Answers (1)

Alan Weiss
Alan Weiss on 5 Dec 2016
To set options, set an options structure using optimset, and then make sure that you pass the options structure to fminsearch, as in this example. Don't use optimset inside a loop.
You can definitely set MaxFunEvals and MaxIter to positive integer values. If you find that you cannot, then you are most likely not passing the options structure to fminsearch.
Alan Weiss
MATLAB mathematical toolbox documentation
  2 Comments
Gorkem
Gorkem on 5 Dec 2016
Edited: Gorkem on 5 Dec 2016
so you are saying that I can do the following?
options = optimset('MaxFunEvals',50,'MaxIter',50);
x = fminsearch(fun,x0,options);
Alan Weiss
Alan Weiss on 5 Dec 2016
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!