How to break down fminsearch in execution
2 views (last 30 days)
Show older comments
My goal is to find the optimum position of my actuator to get the smallest spot size in a CCD image.
In order to do that,I have the code to fit the current spot size at any actuator position.
My plan is like this: I have an initial actuator position x0 and thus the corresponding initial spot size r0 from the code; Then I can try another actuator position, say x1, by some algorithm. Then my actuator goes to x1 and the spot size can be fitted to be r1 with that actuator position. Then my algorithm tells me the next attempt actuator position x2, then r2, x3, r3..... until the optimum actuator position is found.
I am working with fminsearch function. But the problem is that, fminsearch works as the an entity. I can't do step by step process to determine my x and fit my r as a feedback to make it continue to work.
I am trying to think whether I can break fminsearch so that I can interrupt to get the x and tell it the r after fitting.
Anyone has any suggestion?
Thanks a lot!
1 Comment
Rik
on 15 Jan 2019
The doc mentions the algorithm used. I think you might have to reimplement it to only have a single iteration.
Accepted Answer
Steven Lord
on 15 Jan 2019
So you want the optimizer to show you some information then wait for you to perform some sort of experiment and provide the answer from that experiment as the value for your "objective function"? That's possible.
function x = example439803
x = fminsearch(@askUserForAnswer, 0);
function y = askUserForAnswer(x)
y = input(sprintf('Enter x.^2 - x - 2 for x = %g: ', x));
% y = x.^2-x-2;
fminsearch doesn't really care how your function computes the value it returns. Of course, for this simple example, it would be much quicker to use the commented line in askUserForAnswer instead.
3 Comments
Steven Lord
on 15 Jan 2019
What form does "the experiment" take? If it's calling some other executable, depending on whether or not it allows other software to control it (via COM, for example, or by passing in arguments when you call it using system) that would work as well.
More Answers (0)
See Also
Categories
Find more on PID Controller Tuning 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!