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

1 vue (au cours des 30 derniers jours)
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 commentaires
John D'Errico
John D'Errico le 13 Nov 2022
Modifié(e) : John D'Errico le 13 Nov 2022
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 le 14 Nov 2022
Modifié(e) : Jan le 14 Nov 2022
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.

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 14 Nov 2022
Modifié(e) : Jan le 14 Nov 2022
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 commentaire
Jan
Jan le 14 Nov 2022
@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.

Connectez-vous pour commenter.

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by