フィルターのクリア

not enough input arguments

2 ビュー (過去 30 日間)
aaliyan javaid
aaliyan javaid 2021 年 4 月 8 日
コメント済み: aaliyan javaid 2021 年 4 月 9 日
i am trying to run the built in matlab function for particle swram i have defined the objective function spearately na then called that function here is the code
function f = objective(p1,q1,p2,n,m)
f = (p1 * q1 + p2 * n * m );
end
objfcn = @objective;
nvar = 5;
lb = [-5 -5];
ub = [5 5];
options = optimoptions('particleswarm','swarmsize',100);
f = particleswarm(objective,nvar,lb,ub,options);
kindly help thanks
  1 件のコメント
aaliyan javaid
aaliyan javaid 2021 年 4 月 8 日

サインインしてコメントする。

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 4 月 8 日
You have not set up your objective function correctly, and then you are also not passing it correctly to particleswarm.
  • Write the objective function to accept a row vector of length nvars and return a scalar value.
This meains a single input variable, where each column corresponds to the values of each variable. You can split that vector into specific variables inside the objective function if you want, as I do below.
Also, your 'fun' input to particleswarm should be either objfcn or @objective.
nvar = 5;
lb = [-5 -5];
ub = [5 5];
opts = optimoptions('particleswarm','swarmsize',100);
f = particleswarm(@objective,nvar,lb,ub,opts);
function f = objective(params)
p1=params(1);
q1=params(2);
p2=params(3);
n=params(4);
m=params(5);
f = (p1 * q1 + p2 * n * m );
end
Note that this will run now, but it did not find a solution before it was terminated.
  1 件のコメント
aaliyan javaid
aaliyan javaid 2021 年 4 月 9 日
thanks alot for the help

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by