MATLAB: Using derivatives function, diff and GA toolbox

diff()genetic algorithm toolbox.MATLAB

Hi,
I wrote a code using diff function to model some parameters. Now, I need to adjust some parameters with GA Matlab Toolbox. The parameters that I am aiming to optimize, have been used in the diff function, as well.
Is that work? I mean, can I optimize parameters that is used in the diff function? If yes, useing diff may decrease the spead of calculation? Is it recommneded to apply analytican deriviative instead of diff approximation?
Tnx

Best Answer

You don't show any code, so my answer might be irrelevant.
Are you using diff as a symbolic derivative or as a standard MATLAB finite difference? If you are using a symbolic derivative, then ga does not apply until you convert the symbolic function to a standard MATLAB function using, for example, matlabFunction. See Symbolic Math Toolbox Calculates Gradients and Hessians.
But this brings up a more important point. If your problem is smooth, then don't use ga. Instead, use an appropriate Optimization Toolbox solver such as fmincon. Or for a global solution instead of a local solution, use MultiStart. I assume that your problem is smooth because you talk about analytic derivatives.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation