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

1 回表示 (過去 30 日間)
MUNKHBOLOR BAIGALI
MUNKHBOLOR BAIGALI 2020 年 9 月 10 日
コメント済み: MUNKHBOLOR BAIGALI 2020 年 9 月 10 日
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).
MUNKHBOLOR BAIGALI
MUNKHBOLOR BAIGALI 2020 年 9 月 10 日
yes. I understood thank you sir

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

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by