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?

 採用された回答

Alan Weiss
Alan Weiss 2015 年 11 月 11 日

0 投票

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 件のコメント

Naveed Khan
Naveed Khan 2015 年 11 月 11 日
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 2015 年 11 月 12 日
編集済み: Alan Weiss 2015 年 11 月 12 日
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
Naveed Khan
Naveed Khan 2015 年 11 月 12 日
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
Alan Weiss
Alan Weiss 2015 年 11 月 12 日
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
Naveed Khan
Naveed Khan 2015 年 11 月 12 日
Thanks a lot Alan Weiss, your answer and guidance really help me and solve my problem, once again thanks a lot

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2015 年 11 月 11 日

コメント済み:

2015 年 11 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by