Optimization running. Error running optimization. Your fitness function must return a scalar value.
33 views (last 30 days)
Show older comments
esiotlab GEC on 17 Mar 2022
Commented: Geoff Hayes on 23 Mar 2022
function c= opt(x)
p1 = -0.0001759;
p2 = 0.03395 ;
p3 = 5.987 ;
c = p1.*x.^2 + p2.*x + p3;
Can anybody help to resolve the error
Geoff Hayes on 17 Mar 2022
@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.
Geoff Hayes on 23 Mar 2022
Torsten on 17 Mar 2022
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.
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!