Question about GA and the fun.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hongwei Zhuang
le 30 Juil 2020
Réponse apportée : Stephan
le 30 Juil 2020
I have an objective function : y = error_RT(Tx,Ty,theta,T1,T2) .The Tx,Ty,theta are the parameters to be solved , while the T1&T2 are constants calculated by other programs. The GA needs a @fun(x), but I don't know how to pass the constants I know to the program.
Code:
x = ga(y,3,[],[],[],[],[0,-2,-2],[pi,2,2]);
function y = error_RT(Tx,Ty,theta,T1,T2)
T = [Tx;Ty];
R = [cos(theta),sin(theta);-sin(theta),cos(theta)];
[m,~] = size(T1);
[n,] = size(T2);
for i = 1:m
T1(i,n)=(R*T1(i,n)'+T')';
end
Test1 = zeros(600,600);
Test2 = zeros(600,600);
for i = 1:m
Test1(round(T1(i,1)*100),round(T1(i,2)*100)) = Test1(round(T1(i,1)*100),round(T1(i,2)*100)) + 1;
end
for i = 1:n
Test2(round(T2(i,1)*100),round(T2(i,2)*100)) = Test2(round(T2(i,1)*100),round(T2(i,2)*100)) + 1;
end
y = sum(sum((Test1-Test2).^2));
end
0 commentaires
Réponse acceptée
Stephan
le 30 Juil 2020
Have a read here:
In your case it should look somehow like this:
x = ga(@(vars)error_RT(vars,T1,T2) ,3,[],[],[],[],[0,-2,-2],[pi,2,2]);
function y = error_RT(vars,T1,T2)
Tx = vars(1);
Ty = vars(2);
theta = vars(3);
... % your function code
... % your function code
... % your function code
end
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Testing Frameworks dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!