Genetic Algorithm, argument should be real?

3 visualizaciones (últimos 30 días)
Andy Rahmawan
Andy Rahmawan el 1 de Oct. de 2012
Hi all.. I want to ask about my objective function :
function f = function1(x)
p=(atand((x(4))/(x(5)-100)));
g=(((x(5)-100)^2+x(4)^2)^0.5);
s=((x(1)^2+g^2-x(2)^2)/(2*x(1)*g));
t=((x(2)^2+g^2-x(1)^2)/(2*x(2)*g));
alpha=((acosd(s))+p);
betha=((acosd(t))-p);
f=((x(2)*sind(alpha+betha))/(2*x(3)*cosd(betha)));
after execution with genetic algorithm solver the result are :
??? Error using ==> sind at 16 Argument should be real.
Error in ==> fungsi1 at 8 f=((x(2)*sind(alpha+betha))/(2*x(3)*cosd(betha))); Error in ==> validate>@(x)fitness(x,FitnessFcnArgs{:}) at 135 fitness = @(x) fitness(x,FitnessFcnArgs{:});
Error in ==> fcnvectorizer at 23 y = fun(pop);
Error in ==> makeState at 48 Score = fcnvectorizer(state.Population(initScoreProvided+1:end,:),FitnessFcn,1,options.SerialUserFcn);
Error in ==> gaunc at 41 state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ==> ga at 279 [x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
sind not real argument? why? because value of p not real?
[EDITED, Jan, code formatted]
  1 comentario
Jan
Jan el 1 de Oct. de 2012
Please learn how to format your code. It is easy and has been explained repeatedly. Thanks.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 1 de Oct. de 2012
Editada: Jan el 1 de Oct. de 2012
If p is not real, alpha and betha are not real also in general. Then even alpha+betha is not real also in general. And then sind() cannot operate on this value, as the error message clearly explains.
You can use the debugger to observe the values of the local variables to find the reasons for the imaginary values.
  3 comentarios
Jan
Jan el 1 de Oct. de 2012
Editada: Jan el 1 de Oct. de 2012
Please, Andy, format your code properly. A bad readability is not useful, when you want to get help.
Again I suggest to use the debugger to find the reason for the imaginary values. We do not have your input data, such that we cannot do the debugging for you. E.g.:
dbstop if error
Now Matlab stops when the error occurres and you can check the values of the local variables in the command window or workspace browser.
Andy Rahmawan
Andy Rahmawan el 1 de Oct. de 2012
%code starts from here
function f = function1(x)
p=(abs(atand((x(4))/(x(5)-100))));
g=(((x(5)-100)^2+x(4)^2)^0.5);
s=((x(1)^2+g^2-x(2)^2)/(2*x(1)*g));
t=((x(2)^2+g^2-x(1)^2)/(2*x(2)*g));
alpha=((acosd(s))+p);
betha=((acosd(t))-p);
f=((x(2)*sind(alpha+betha))/(2*x(3)*cosd(betha)));
this code u mean? sorry i'm noob here..
then i use absolute on value of p, then GA still didn't work,, what happened?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Genetic Algorithm en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by