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 天)
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 CenterFile Exchange 中查找有关 Particle Swarm 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by