Inner matrix dimensions must agree error in ga

1 view (last 30 days)
Hi every one
I have this function and constraint as below for optimizing by ga.
function=1.11e-4*((z).^2)-(4.46e3*(z))
A=[1;-1]
b=[1.97e8;0]
P1= ga(@(z) (1.11e-4*((z).^2)-(4.46e3*(z))),1,[1;-1],[1.97e8;0]);
and after run this error apears:
Error using *
Inner matrix dimensions must agree.
Error in isTrialFeasible (line 59)
constrViolation = Aineq*X-bineq;
Error in gacreationlinearfeasible>feasibleLHS (line 187)
feasible = isTrialFeasible(initialPopulation,linCon.Aineq,linCon.bineq, ...
Error in gacreationlinearfeasible (line 41)
feasiblePop = feasibleLHS(individualsToCreate,GenomeLength,options);
Error in makeState (line 29)
state.Population = feval(options.CreationFcn,GenomeLength,FitnessFcn,options,options.CreationFcnArgs{:});
Error in galincon (line 17)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 359)
[x,fval,exitFlag,output,population,scores] = galincon(FitnessFcn,nvars, ...
Error in checknevis (line 1)
P1= ga(@(z) (1.11e-4*((z).^2)-(4.46e3*(z))),1,[1;-1],[1.97e8;0]);
>>
what should i do???

Accepted Answer

Star Strider
Star Strider on 3 Apr 2022
There is only one parameter, however it has two conflicting constraints.
The constraints are:
Unless there is something about this that I am missing, it would probably be better to put those as the ‘lb’ and ‘ub’ bounds instead:
lb = 0;
ub = 1.98e8;
P1= ga(@(z) (1.11e-4*((z).^2)-(4.46e3*(z))),1,[],[],[],[],0,1.9e8)
Optimization terminated: average change in the fitness value less than options.FunctionTolerance.
P1 = 1.8422e+07
.

More Answers (0)

Categories

Find more on Mathematics 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!