How to call a function with multi variable in real coded GA in function handle and how to define upper and lower bound of that variable in matlab?
Mostrar comentarios más antiguos
I have defined a function with many variable
Example: function T= Torque(a,b,c)
where a,b,c is variable having upper and lower bound 1<a<3; 2<b<7; 6<c<7
T=a^2 + 3a + b*c +b^2 + a*b*c + c^2
In GA code I have used function handle for calling torque function and also defined the bounds of variables as
lb=[1 2 6] % lower bound of variable
ub=[3 7 7] % upper bound of variable
prob=@Torque
while calculating the fitness function error shows "Not enough input arguments"
Please suggest me how to resolve this issue.
Respuesta aceptada
Más respuestas (1)
Steven Lord
el 19 de En. de 2022
If you've defined Torque to accept 3 inputs as per the code at the end of this answer, you can still use that function in your ga call. You just need an adapter, like a plumbing fitting to connect different sized pipes. This is one of the approaches described in the documentation page "Passing Extra Parameters" linked to in the Tips section of the ga documentation page.
callFunctionNoAdapter = Torque(1, 2, 3)
adapter = @(x) Torque(x(1), x(2), x(3));
callFunctionAdapter = adapter([1 2 3])
The function handle adapter accepts 1 input as ga requires. It calls Torque with three inputs as Torque requires. It passes the output from Torque back to ga as ga requires. Both ga and Torque are happy.
function T= Torque(a,b,c)
T = a + 2*b + 3*c; % sample
end
Categorías
Más información sobre Nearest Neighbors en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!