Calling Multiple Input Variable for Genetic Algorithm

4 ビュー (過去 30 日間)
Farinaz Kooshki
Farinaz Kooshki 2020 年 4 月 10 日
コメント済み: Harshit Jain 2021 年 4 月 25 日
Hi,
I am trying to call simple multiple input variable by GA while I face error, Would you please help me how to solve the issue,
The main function is :
function R = Final(a,b,k)
R=a(1)a(2)+b+k;
end
and tried to use GA for it as below:
clc, clear, close all
FitFcn= @(a,b,k)Final(a,b,k);
nvars=4;
[a,b,k,fval]= ga(@(a,b,k)FitFcn,nvars);
Please support me to know how to use GA for multi variable
  1 件のコメント
Harshit Jain
Harshit Jain 2021 年 4 月 25 日
Hi ,
I am trying to Optimise the Single Objective - Multi Variable Optimization problem involving 7 Variables with the help of Genetic Algorithm, but found errors in GA handling function. Could you please explain how to call function using GA Handler?

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

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 10 日
編集済み: Ameer Hamza 2020 年 4 月 10 日
This is the correct code. Compare it with your code to see how to input a function handle to ga() properly.
clc, clear, close all
FitFcn= @(a,b,k)Final(a,b,k);
nvars=4;
[x,fval]= ga(@(x) FitFcn(x(1:2),x(3),x(4)),nvars);
a_solution = x(1:2);
b_solution = x(3);
k_solution = x(4);
function R = Final(a,b,k)
R=a(1)*a(2)+b+k;
end
  2 件のコメント
Farinaz Kooshki
Farinaz Kooshki 2020 年 4 月 10 日
I get the point from your solution, thanks a lot.
Ameer Hamza
Ameer Hamza 2020 年 4 月 10 日
Glad to be of help.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by