Inner matrix dimensions must agree error in ga

2 visualizaciones (últimos 30 días)
shirin mhd
shirin mhd el 3 de Abr. de 2022
Comentada: Star Strider el 3 de Abr. de 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???

Respuesta aceptada

Star Strider
Star Strider el 3 de Abr. de 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 comentarios
shirin mhd
shirin mhd el 3 de Abr. de 2022
I'm really thankful for your help.
Star Strider
Star Strider el 3 de Abr. de 2022
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by