필터 지우기
필터 지우기

Inner matrix dimensions must agree error in ga

조회 수: 1 (최근 30일)
shirin mhd
shirin mhd 2022년 4월 3일
댓글: Star Strider 2022년 4월 3일
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???

채택된 답변

Star Strider
Star Strider 2022년 4월 3일
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
shirin mhd
shirin mhd 2022년 4월 3일
I'm really thankful for your help.
Star Strider
Star Strider 2022년 4월 3일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by