フィルターのクリア

Hi ,I need some help with this PSO optimization code, "not enough input arguments "error message (Main pso used is The yarpiz's).

1 回表示 (過去 30 日間)
Anwar
Anwar 2022 年 11 月 13 日
コメント済み: Jan 2022 年 11 月 14 日
function Y1 = costfunction(x)
V = 384*ones(1,10);
Q = 60*ones(1,10);
N = 0.4*ones(1,10);
R = [7, 12, 8, 11, 9, 13, 7, 12, 10, 6];
Sbk = [1,-1,1,-1,1,-1,1,-1,1,-1];
for k=2:10
y(1)=((V(1)*(x(1)-0.3)*Q(1)*R(1))/N(1))*((1+Sbk(1))/2)*Sbk(1)^2+...
(V(1)*(0.3-x(1))*Q(1)*R(1))*((1+Sbk(1))/2)*Sbk(1)^2;
y(k)=((V(k)*(x(k)-x(k-1))*Q(k)*R(k))/N(k))*((1+Sbk(k))/2)*Sbk(k)^2+...
(V(k)*(x(k-1)-x(k))*Q(k)*R(k))*((1+Sbk(k))/2)*Sbk(k)^2;
Y1 = sum(y);
end
end
  2 件のコメント
John D'Errico
John D'Errico 2022 年 11 月 13 日
編集済み: John D'Errico 2022 年 11 月 13 日
When you post a PICTURE of your code, you make it impossible for someone to help you. Do you expect someone to jump to type in that mess of code?
Is there a reason why you want to make it more difficult for somone to help you? Is that really your goal here?
I might comment also that it seems silly to redefine y(1) INSIDE the loop, since y(1) should only ever be defined once. And then, even sillier to compute Y1 = sum(y) INSIDE the loop. If you like to waste CPU cycles that badly, computing things over and over again for no reason, I can't wait until you have a significant piece of code that runs too slowly, and you want help then.
Jan
Jan 2022 年 11 月 14 日
編集済み: Jan 2022 年 11 月 14 日
A hint: The readers are not all "guys" and I am not your buddy, but I do not know, if John is.
I have problems to read the tiny image of your objective function.

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

回答 (1 件)

Jan
Jan 2022 年 11 月 14 日
編集済み: Jan 2022 年 11 月 14 日
I'm not sure what you are asking for, but this is simplified version of your function without a loop:
function Y1 = costfunction(x)
dx = [x(1) - 0.3, diff(x)];
V = 384;
Q = 60;
N = 0.4;
R = [7, 12, 8, 11, 9, 13, 7, 12, 10, 6];
Sbk = [1,-1,1,-1,1,-1,1,-1,1,-1];
y = (V * dx * Q .* R * (1 / N - 1)) .* ((1 + Sbk) / 2) .* Sbk.^2;
Y1 = sum(y)
end
  1 件のコメント
Jan
Jan 2022 年 11 月 14 日
@Abdelkrim: Remember, that for Matlab these are all numbers. So for a solution, the programmer does not need any of the information about the meaning of the values, because the code does not need it also.

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

カテゴリ

Help Center および File ExchangeParticle Swarm についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by