0
votes

I wrote the following function in MATLAB:

function EX_EFFICIENCY=EXERGY_EFFICIENCY_FUNCTION(CR,ER,PC,T0,P0)

I used the following order (ga):

x = ga(@EXERGY_EFFICIENCY_FUNCTION,5)

But it gets the error:

Not enough input arguments.

Error in EXERGY_EFFICIENCY_FUNCTION (line 22) T7p=T0.*(PC.^((k-1)./k));

Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11) fcn_handle = @(x) fcn(x,FcnArgs{:});

Error in makeState (line 47) firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));

Error in gaunc (line 40) state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);

Error in ga (line 398) [x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...

Caused by: Failure in initial user-supplied fitness function evaluation. GA cannot continue.

How can I minimize this function?

1
Minimize? Optimize? You mean fix? ga wants the handle to a function with one input argument. You give it one that needs 5 arguments. That will not work, of course.Cris Luengo

1 Answers

1
votes

What are the variables you want to minimize over? All five CR,ER,PC,T0,P0? Then you need to tell ga to use a length-5-vector and deal its elements to the input arguments of the function. Like this:

xopt = ga(@(x) EXERGY_EFFICIENCY_FUNCTION(x(1),x(2),x(3),x(4),x(5)), 5);

You can also fix some and optimize over the others of course, like this:

xopt = ga(@(x) EXERGY_EFFICIENCY_FUNCTION(x(1),x(2),PC,T0,P0), 2);

optimizes CR, ER for fixed values of PC,T0, and P0.