フィルターのクリア

GA is not working...Function i have written separately calling in main program but not worked??

1 回表示 (過去 30 日間)
xdata =[ 1 2 3 4 5 6] ; ydata=(1./(xdata.^2+2*xdata+4)); FitnessFunction = @simple_fitness; numberOfVariables = 3; x =ga(@genefun,numberOfVariables) * function y = simple_fitness(x,xdata,ydata) y = @(x) sum((x(1)./(x(2).*xdata.^1.9+x(3).*xdata.^0.9+1) - ydata).^2);**

採用された回答

Sergey Kasyanov
Sergey Kasyanov 2018 年 4 月 6 日
There are two version of code which are working but do not converge.
First:
xdata =[ 1 2 3 4 5 6] ;
ydata=(1./(xdata.^2+2*xdata+4));
FitnessFunction = @(x) sum((x(1)./(x(2).*xdata.^1.9+x(3).*xdata.^0.9+1)-ydata).^2);
numberOfVariables = 3;
x =ga(FitnessFunction,numberOfVariables)
Second:
xdata =[ 1 2 3 4 5 6] ;
ydata=(1./(xdata.^2+2*xdata+4));
numberOfVariables = 3;
x =ga(FitnessFunction,numberOfVariables)
%in separate file
function y=simple_fitness(xdata,ydata)
y=@(x) sum((x(1)./(x(2).*xdata.^1.9+x(3).*xdata.^0.9+1)-ydata).^2)
end
  2 件のコメント
ash
ash 2018 年 4 月 7 日
now it is working but every run i am getting different values of x for same y...why??
Sergey Kasyanov
Sergey Kasyanov 2018 年 4 月 7 日
I don't know. I barely corrected your code.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLanguage Fundamentals についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by