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

1 vue (au cours des 30 derniers jours)
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 -------------------------------------------------

Réponses (1)

Ameer Hamza
Ameer Hamza le 10 Sep 2020
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 commentaires
Ameer Hamza
Ameer Hamza le 10 Sep 2020
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).

Connectez-vous pour commenter.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by