Multi-variable Fitness Function error using Optimization Tool

function f = objfun(x,t) f = x.*(t-x); end
When i try to use this code as a fitness function using MATLAB's Optimization Tool and the Genetic Algorithm (ga) solver, i get the following error:
Error running optimization. Not enough input arguments.
I know the function has only 2 variables and I'm passing it those few variables so I have no idea why I am getting this error. Can someone please help me fix this?

 Respuesta aceptada

Alan Weiss
Alan Weiss el 11 de Nov. de 2015
Global Optimization Toolbox solvers optimize functions of one vector variable. You need to put all your variables into one vector, as in the example.
Alan Weiss
MATLAB mathematical toolbox documentation

5 comentarios

Thanks Alan for your fruitful response. Can i give different specific values to both variables like (x,t) e.g. x= .1, .3, .5, .9 and to t= 20, 40, 60, 80. Is it possible through Global Optimization Toolbox?
Alan Weiss
Alan Weiss el 12 de Nov. de 2015
Editada: Alan Weiss el 12 de Nov. de 2015
It depends on what you are trying to do. If you want to optimize one variable while holding another fixed. then you can regard the fixed variable as an extra parameter.
Alan Weiss
MATLAB mathematical toolbox documentation
I appologize, i didnt understand it properly. Or may be i am not clear. I have for example two variables. and both are a sequence. i.e. for variable 'a' it starts from 0.1 and ends on 1. Whereas, variable 'b' starts from 0.005 till 0.5.
While using GA with one input it asks for Min and max value and than it divide it randomly. So how can i do that with two or more than one variables.
Or how can i give min and max for more than one variables. Thanks
If you are asking how to set bounds for different components of your variable vector, see the documentation on bounds. If you are asking something else, then I am sorry, but I don't understand.
Alan Weiss
MATLAB mathematical toolbox documentation
Thanks a lot Alan Weiss, your answer and guidance really help me and solve my problem, once again thanks a lot

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 11 de Nov. de 2015

Comentada:

el 12 de Nov. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by