Genetic Algorithm, argument should be real?

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일

0 개 추천

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

then i use absolute on value of p, then GA still didn't work,, what happened?
??? Error using ==> sind at 16 Argument should be real.
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)));
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.
%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개)

카테고리

질문:

2012년 10월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by