Genetic Algorithm, argument should be real?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Jan
il 1 Ott 2012
Please learn how to format your code. It is easy and has been explained repeatedly. Thanks.
Risposta accettata
Jan
il 1 Ott 2012
Modificato: Jan
il 1 Ott 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 Commenti
Jan
il 1 Ott 2012
Modificato: Jan
il 1 Ott 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Genetic Algorithm in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!