How to pass variables to the fintness function in Genetic algorithm?

1 回表示 (過去 30 日間)
Mariem Harmassi
Mariem Harmassi 2012 年 10 月 8 日
回答済み: M Mirrashid 2022 年 6 月 5 日
hello I am testing a Genetic algorithm without using the global optimization toolbox, I have defined the fitness function in a separtae matlab file and it is called by the main program with ga function ,in my fitness function i need some parametrs from the main function .Can someone tell me hwo to do this ?? I thought about declaring the variables as global variables but it doesn t work ?

採用された回答

Alan Weiss
Alan Weiss 2012 年 10 月 10 日
Alan Weiss
MATLAB mathematical toolbox documentation
  1 件のコメント
Mariem Harmassi
Mariem Harmassi 2012 年 10 月 11 日
Hello Alan thank u for the answer , i saw the documentation but it seems not possible to call the ga with f = @(x)parameterfun(x,a,b,c) i must call the fminunc function [x,fval] = fminunc(f,x0) :-/ :-(

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

その他の回答 (3 件)

Alan Weiss
Alan Weiss 2012 年 10 月 11 日
I'm sorry, I do not understand you. It is indeed possible to call the fitnes function with f = @(x)parameterfun(x,a,b,c). If you want more help, you will need to provide more information. Specifically:
1. Your function signature (function f = parameterfun(x,a,b))
2. Your calling syntax (x = ga(f,n,A,b))
3. All output MATLAB gives. I mean all, not an edited version.
Alan Weiss
MATLAB mathematical toolbox documentation
  1 件のコメント
Mariem Harmassi
Mariem Harmassi 2012 年 10 月 13 日
thank u a lot Alan i tested it and it works so i am very happy :)))

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


Alex Omar Topa Gavilema
Alex Omar Topa Gavilema 2022 年 6 月 3 日
I have the same problem. how did you do it?

M Mirrashid
M Mirrashid 2022 年 6 月 5 日

カテゴリ

Help Center および File ExchangeGenetic Algorithm についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by