i'm getting Error using ga (line 305) help me

2 views (last 30 days)
Objective function
function z=my_fun(x)
z=x(1)+2*x(2)+56*x(3)+100;
constrain function
function [c]=const(x)
x=[6,3,4];
c1=(6<=x(1)<=100);
c2=(2<=x(2)<=4);
c3=(2<=x(3)<=4);
c=[c1;c2;c3];
main script
clear all
clc
nvars=3;
LB=[6 2 2];
UB=[100 4 4];
[x, fval]=ga(my_fun,nvars,[],[],[],[],[],[],LB,UB,@const)
when excecuted getting error
Error using ga (line 305)
Tenth input argument must be a valid structure created with GAOPTIMSET.
Error in start (line 6)
[x, fval]=ga(@my_fun,nvars,[],[],[],[],[],[],LB,UB,@const)
please help me by necessary changes to coding..

Accepted Answer

Geoff Hayes
Geoff Hayes on 4 Apr 2015
Arunachalam - the error message is telling you that the tenth parameter/argument to the ga function is not the options object that should be created with the gaoptimset function. Instead, the tenth argument corresponds to UB, the array of upper bounds. If you look at the documentation for ga you will not that you are passing too many input parameters/arguments for what you have in mind. Your call to ga should be reduced to (according to the 2015a documentation)
x = ga(@my_fun,nvars,[],[],[],[],LB,UB,@const);
Note that you may also want to review the nonlcon documentation as it would appear that this function (your const) should return two outputs).

More Answers (0)

Community Treasure Hunt

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

Start Hunting!