MATLAB Answers

Using derivatives function, diff and GA toolbox

2 views (last 30 days)
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?


Sign in to comment.

Accepted Answer

Alan Weiss
Alan Weiss on 1 Sep 2020
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


Sepideh Alimohamamdi
Sepideh Alimohamamdi on 1 Sep 2020
Thanks for your answer. Let me explain the code.
Adjustable parameters : m=[m1 m2 m3 m4 m5]
Analythical calculations to fit target value, P=f(m,etta).
while error>10e-8
P_cal is calculated based on initial values and analytical equations and then compared with actual P values from experiments and error is calculated.
So, finding the proper m matrix by GA while using diff function was used in my code. I was wondering if I can use diff function with GA, since the m matrix is used in diff function, as well.
Alan Weiss
Alan Weiss on 1 Sep 2020
It appears the you are trying to use a Newton step to find the best fitting parameters for data. I think that you should use the solvers designed for this, lsqcurvefit or lsqnonlin to solve your problem, instead of ga. If you can supply analytic derivatives for your objective function, you can indicate so using the SpecifyObjectiveGradient option.
Alan Weiss
MATLAB mathematical toolbox documentation

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!

Translated by