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?

 採用された回答

Alan Weiss
Alan Weiss 2016 年 11 月 22 日
Alan Weiss
MATLAB mathematical toolbox documentation

2 件のコメント

Geetika Bagga
Geetika Bagga 2016 年 11 月 23 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2016 年 11 月 22 日

コメント済み:

2016 年 11 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by