How to break down fminsearch in execution

3 visualizaciones (últimos 30 días)
Xinpeng Du
Xinpeng Du el 15 de En. de 2019
Comentada: Xinpeng Du el 16 de En. de 2019
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 comentario
Rik
Rik el 15 de En. de 2019
The doc mentions the algorithm used. I think you might have to reimplement it to only have a single iteration.

Iniciar sesión para comentar.

Respuesta aceptada

Steven Lord
Steven Lord el 15 de En. de 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 comentarios
Steven Lord
Steven Lord el 15 de En. de 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.
Xinpeng Du
Xinpeng Du el 16 de En. de 2019
'The experiment' is to control the real actuator go to the real position x, then camera will grab an image frame and fit the spot size as y.
The entire system is controled by LabVIEW.
Those MATLAB code is going to be called by LabVIEW, too.
The process is like this: initialization (get x0) -> actuator motion (go to x0) -> grab an image and fit (get y) -> fitting (fminsearch gets the next position x1) -> actuator motion (go to x1)...... and so on.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by