필터 지우기
필터 지우기

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