problem in optimization by MATLAB using genetic algorithm

4 views (last 30 days)
the first picture is the fitness equation code
then I checked the function code and it works, after that I write the following codes in a new script called main
and after that i have save this script, but when I write ' main' in the command window it gives me such errors
can any one help please

Accepted Answer

Stephan on 25 Nov 2019
Change myFitness.m to:
function y = myFitness(x)
s = x(1)
z = x(3)
x = x(2)
also change this line your main function to:
[x, fval] = ga(...)
The optimizers in Matlab wil accept all the single optimization variables only as a vector. To pass additional vectors / values to the objective function see passing extra parameters.
BTW: Please post code intstead of pictures of code.

Sign in to comment.

More Answers (1)

Philippe Lebel
Philippe Lebel on 25 Nov 2019


Find more on Problem-Based Optimization Setup 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!