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 Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by