I want to calculate some function using PSO algoritm. but it doesn't work please help me.

Hello I want to calculate some function using PSO algoritm. In 'myfunc' file -----> When x(optimal size) = 0 , 2 , 5, 7 , 8 , 9 , 10, I want to know answer P.
---- myfunc m-file saved.
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
Then, I called myfunc file in PSO code.
BUT it doesn't work. ANOTHER 'M-FILE' S WORKS.
this below figure is myfunc result ----
Please tell me why myfunc doesn't work.

Answers (1)

Yu are trying to do element by element multiplication of a vector that has 7 elements (x) by a vector that has 12 elements (G/Gref ... etc), in
P = ((Ppv_rated * x) .* ((G/Gref).*(1 + Kt*(Tc - Tref )))')'

6 Comments

Sorry sir I want to calculate each x = 0,2,5,7,8,9,10
So I changed .*
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 ];
%x = [0,2,5,7,8,9,10 ] ;
Tc = Tamb + (0.0256 * G ) ;
P = ((Ppv_rated * x) * ((G/Gref).*(1 + Kt*(Tc - Tref )))')';
end
AND RESULT IS
Do you mean something like this:
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 ) ;
for i = 1:numel(x)
P(i,:) = ((Ppv_rated * x(i)) * ((G/Gref).*(1 + Kt*(Tc - Tref )))')';
end
which results in P being a 7 by 12 matrix.
In below figure is calculated without PSO.
I mean, I want to calculate this result with PSO.
but I don't know how to write myfunc m-file using PSO.
Search Matlab's File Exchange for PSO. There are several PSO routines there.

This question is closed.

Products

Release

R2018b

Asked:

on 10 Sep 2020

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!