How can I convert symbolic equation to fitness function which can be evaluated by genetic algorithm
3 views (last 30 days)
Show older comments
Hi,
I have a symbolic equation and wish to convert to a function which can be evaluated by genetic algorithm (ga). I have tried using the matlabFunction and convert the symbolic equation into a matlab file. However, this generated file can only be evaluated by fmincon or patternsearch algorithms and not genetic algorithm. I get this error using ga.
Caused by: Failure in initial user-supplied fitness function evaluation. GA cannot continue.
It seems like the matlabFunction does not generate the format required by ga, can anyone please advise what's the solution/workaround to this problem?
Thanks!
0 Comments
Answers (3)
Alan Weiss
on 22 Jan 2014
fmincon and patternsearch expect that the variable x is a column, though they are pretty forgiving if it is something else. ga expects that x is a row. So perhaps you should have
X = sym('x',[1 2*N]);
I could not check this because I do not know what P and price are.
Alan Weiss
MATLAB mathematical toolbox documentation
1 Comment
Ashley Thornton
on 20 Aug 2015
Thanks so much. I was having the exact same problem, your solution worked a treat.
Walter Roberson
on 21 Jan 2014
Please show symvars() of the symbolic expression, and show the call to matlabFunction that you used. Please also show the first bit of the generated function -- in particular, the part inside the @() header. Please show your call to ga()
0 Comments
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!