I want to calculate any function using PSO algorithm. but It doesn't work. please help

조회 수: 1 (최근 30일)
Hello, I want to calculate any function using PSO algorithm.
ex: Sphere m-file is good working. BUT myfunc is not working. please show in below images
m-file :
function z = Sphere(x)
z = sum(x.^2);
end
PSO code: call Sphere m-file
Result:
The 'Sphere' function answered.
?????? BUT 'myfunc' is not answered.
m-file : myfunc
function [Tc, P] = myfunc ()
Ppv_rated = 250 ;
G = [5.75, 6, 6.365, 6.5, 6.185, 5.75, 5, 4.8, 5.5, 6.18, 6.15, 5.8 ];
Gref = 1000 ;
Kt = -0.485 ;
Tref = 25 ;
Tamb = [25.63, 26.7, 26.610, 25.46, 24.9, 24.01, 23.16, 23.01, 23.54, 23.78, 24.45, 25.3 ];
x = [0,2,5,7,8,9,10 ] ;
Tc = Tamb + (0.0256 * G ) ;
P = ((Ppv_rated * x) .* ((G/Gref).*(1 + Kt*(Tc - Tref )))')';
end
PSO code: call myfunc
Result:
Please tell me why myfunc is not working in PSO code -------------------------------------------------

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 9월 10일
On this line
P = ((Ppv_rated * x) .* ((G/Gref).*(1 + Kt*(Tc - Tref )))')'c % <-- remove this c, it is syntax error in MATLAB.
Remove the 'c' character and replace it with semicolon (;).
Also, right now your function does not take input x, change it like this
function [Tc, P] = myfunc (x)
Ppv_rated = 250 ;
G = [5.75, 6, 6.365, 6.5, 6.185, 5.75, 5, 4.8, 5.5, 6.18, 6.15, 5.8 ];
Gref = 1000 ;
Kt = -0.485 ;
Tref = 25 ;
Tamb = [25.63, 26.7, 26.610, 25.46, 24.9, 24.01, 23.16, 23.01, 23.54, 23.78, 24.45, 25.3 ];
Tc = Tamb + (0.0256 * G ) ;
P = ((Ppv_rated * x) .* ((G/Gref).*(1 + Kt*(Tc - Tref )))')';
end
  댓글 수: 5
Ameer Hamza
Ameer Hamza 2020년 9월 10일
The objective function myfunc must return a single number, but it is returning an array. Change myfunc so that it only returns the value of the objective function (a single number).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Particle Swarm에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by