Optimization running. Error running optimization. Your fitness function must return a scalar value.

6 ビュー (過去 30 日間)
function c= opt(x)
%x=[20,40,60,80,100,120,140,160];
x=20:20:160
p1 = -0.0001759;
p2 = 0.03395 ;
p3 = 5.987 ;
c = p1.*x.^2 + p2.*x + p3;
disp(c);
plot(x,c);
end
Can anybody help to resolve the error

回答 (2 件)

Geoff Hayes
Geoff Hayes 2022 年 3 月 17 日
@esiotlab GEC - it looks like your fitness function is returning an array. You must change your code so that a scalar is returned.
It also looks like you are overwriting the input variable x with an array of values. Why? This defeats the purpose of using the algorithm since all results returned by your fitness function will be the same.
  2 件のコメント
esiotlab GEC
esiotlab GEC 2022 年 3 月 23 日
Sir,
Can I discuss my optimization problem completely.
Could you please provide me your mail id
Geoff Hayes
Geoff Hayes 2022 年 3 月 23 日
@esiotlab GEC - if you wish to discuss the problem here in the forum, then please do so.

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


Torsten
Torsten 2022 年 3 月 17 日
I can't decipher from function "opt" what you are trying to minimize.
But anyhow: your c has dimension 1x8, but it has to be 1x1.

カテゴリ

Help Center および File ExchangeGenetic Algorithm についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by