Genetic Algorithm, argument should be real?

3 次查看(过去 30 天)
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 个评论
Jan
Jan 2012-10-1
Please learn how to format your code. It is easy and has been explained repeatedly. Thanks.

请先登录,再进行评论。

采纳的回答

Jan
Jan 2012-10-1
编辑:Jan 2012-10-1
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 个评论
Jan
Jan 2012-10-1
编辑:Jan 2012-10-1
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 2012-10-1
%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?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by