Inner matrix dimensions must agree error in ga

2 Ansichten (letzte 30 Tage)
shirin mhd
shirin mhd am 3 Apr. 2022
Kommentiert: Star Strider am 3 Apr. 2022
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???

Akzeptierte Antwort

Star Strider
Star Strider am 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
.
  2 Kommentare
shirin mhd
shirin mhd am 3 Apr. 2022
I'm really thankful for your help.
Star Strider
Star Strider am 3 Apr. 2022
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by