Maximizing a Function

15 ビュー (過去 30 日間)
MD NASAR
MD NASAR 2012 年 4 月 21 日
回答済み: mhy 2019 年 3 月 13 日
Dear all
maximizing f(x) = x2 using genetic algorithm,
where x ranges from 0 to 31. Perform 4 iterations. i got his code form one site. code is
%program for Genetic algorithm to maximize the function f(x) =sin(x)
clear all;
clc;
%x ranges from 0 to 3.14
%five bits are enough to represent x in binary representation
n=input('Enter no. of population in each iteration');
nit=input('Enter no. of iterations');
%Generate the initial population
[oldchrom]=initbp(n,5);
%The population in binary is converted to integer
FieldD=[5;0;3.14;0;0;1;1]
for i=1:nit
phen=bindecod(oldchrom,FieldD,3);% phen gives the integer value of the
%binary population
%obtain fitness value
FitnV=sin(phen);
%apply roulette wheel selection
Nsel=4;
newchrix=selrws(FitnV, Nsel);
newchrom=oldchrom(newchrix,:);
%Perform Crossover
crossoverrate=1;
newchromc=recsp(newchrom,crossoverrate);%new population after crossover
%Perform mutation
vlub=0:31;
mutationrate=0.001;
newchromm=mutrandbin(newchromc,vlub,mutationrate);%new population
%after mutation
disp('For iteration');
i
disp('Population');
oldchrom
disp('X');
phen
disp('f(X)');
FitnV
oldchrom=newchromm;
end
when i am ruining this it gave error
??? Undefined function or method 'initbp' for input arguments of type 'double'.
Error in ==> bookcode at 9
[oldchrom]=initbp(n,5);
please some one give me solution
Thank you.
  4 件のコメント
sivakumar c
sivakumar c 2016 年 7 月 11 日
Not only initbp undefined function.In this coding have four undefined function(initbp,bindecod,selrws,recsp).we should implement these funtion code for above coding.
Walter Roberson
Walter Roberson 2016 年 7 月 11 日
It appears that the missing functions might be part of the third-party geatbx toolbox

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

採用された回答

Walter Roberson
Walter Roberson 2012 年 4 月 22 日
initbp() is not a Mathworks-provided function, and it is also not part of any MATLAB File Exchange contribution.
Perhaps you need to download a third-party toolbox, such as http://www.geatbx.com/docu/initbp.html
  1 件のコメント
MD NASAR
MD NASAR 2012 年 4 月 24 日
Thank you sir.
any alternative function in matlab

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

その他の回答 (3 件)

Jan
Jan 2012 年 4 月 22 日
While your code is not readable without formatting (see the "Markup help" link!), the error message seem to be clear: The function "initbp" is not known. Do you expect this function to exist? It is not in the current Matlab path, so perhaps you forgot to add a specific folder?

mado
mado 2013 年 4 月 11 日
Is this function [oldchrom]=initbp(n,5); not existed in higher matlab version
  1 件のコメント
Jan
Jan 2013 年 4 月 11 日
"Higher" than which version do you mean?

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


mhy
mhy 2019 年 3 月 13 日
First,I’m sorry to bother you. It seems that you have the geatbx toolbox. I wonder where you get it, or could you please send one to me? I'm so appreciate for it. Thank you so much. My Email: 1449011027@qq.com

カテゴリ

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