problem in optimization by MATLAB using genetic algorithm

조회 수: 4(최근 30일)
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

채택된 답변

Stephan
Stephan 2019년 11월 25일
Change myFitness.m to:
function y = myFitness(x)
s = x(1)
z = x(3)
x = x(2)
y = ...YOUR EQUATION HERE
end
also change this line your main function to:
[x, fval] = ga(...)
Reason:
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.
  댓글 수: 3
Ola Belal
Ola Belal 2019년 12월 5일
Thank you for your help.

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Philippe Lebel
Philippe Lebel 2019년 11월 25일

태그

Community Treasure Hunt

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

Start Hunting!

Translated by