While implementing genetic algorithm for finding the global minimum for a variable 'y' (which depends upon both x and z), I want to optimise only x and not z. I want to input z from the main code and pass it to my fitness function. Can this be done?

 Risposta accettata

Alan Weiss
MATLAB mathematical toolbox documentation

2 Commenti

Thank you. I will be declaring them as global variables now. So the changes I make to these extra parameters inside the fitness function for my genetic algorithm will be reflected in the main function, right?
I am sorry that you didn't comprehend the documentation. It says not to use global variables. It says that you would be much better served by a line such as
myFitness = @(x) (z^2)*x(1) + 4*x(2) + z*x(2)^5;
or by using nested functions.
Alan Weiss
MATLAB mathematical toolbox documentation

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by