How to optimize the problem?
Mostrar comentarios más antiguos
Hi. I am working on vector inputs to an expression. 'Th' also becomes a vector as output. I want to get 'th' less than 10 but greater than 0. Although I tried to use while loop but it didn't work. How can I get beta and Z as optimum scalar value that generate whole vector 'th' with values less than 10. Below is the code:
a=readtable('Book1.xlsx');
Lat=31.39;
local_long=74.238416;
St_long=75;
long_corr = -4*(St_long - loc al_long);
Solar_altitude = 6;
cosine_h=cos(a.Hour_Angle*pi/180);
sine_h=sin(a.Hour_Angle*pi/180);
cosine_L=cos(Lat*pi/180);
sine_L=sin(Lat*pi/180);
cosine_decl=cos(a.Declination_Angle*pi/180);
sine_decl=sin(a.Declination_Angle*pi/180);
a=addvars(a,cosine_h,'After','Hour_Angle');
a=addvars(a,sine_h,'After','cosine_h');
a=addvars(a,cosine_decl,'After','sine_h');
a=addvars(a,sine_decl,'After','cosine_decl');
n=length(a.Day_Number);
F=sine_decl*sine_L;
G=sine_decl*cosine_L;
H=cosine_decl.*cosine_h*cosine_L;
I=cosine_decl.*cosine_h*sine_L;
J=cosine_decl.*sine_h;
FH = F + H;
IG = I - G;
b=table();
b=addvars(b,FH);
b=addvars(b,IG,'After','FH');
b=addvars(b,J,'After','IG');
beta=45; % Collector Tilt angle
Z=20; % Collector aziuth angle
th= (180/pi*acos(FH*cos(beta*pi/180) + b.IG*sin(beta*pi/180)*cos(Z*pi/180) + b.J*sin(beta*pi/180)*sin(Z*pi/180)));
while th>25
C1 = 0;
B1 = 90;
C2 = -90;
beta = (B1-C1).*rand(1,1) + C1; % Optimum Collector Tilt angle
Z = (B1+C2).*rand(1,1) + C2; % Optimum Collector aziuth angle
th= 180/pi*acos(b.FH*cos(beta*pi/180) + b.IG*sin(beta*pi/180)*cos(Z*pi/180) + b.J*sin(beta*pi/180)*sin(Z*pi/180));
end
Respuesta aceptada
Más respuestas (1)
William Rose
el 18 de Sept. de 2023
1 voto
You ask: "How can I get beta and Z as optimum scalar value that generate whole vector 'th' with values less than 10. "
Please add comments to your code, so that others can understand it. Please describe the meaning of th in words. I understand, from reading your script, that vector th is an agle measured in degrees, and vector th has a different value for each time of day.
long_corr = -4*(St_long - loc al_long);
should be
long_corr = -4*(St_long - local_long);
The table includes the local hour angle and the sun's declination at each time. Your script indicates that beta and Z are the collector tilt and azimuth, respectively. You say you want beta and Z to be scalars (not vectors).
If th() is the angle of the sun from the collector normal, then
- there does not exist a beta and Z such that the th() will be <10 degrees for the entire day
- the calculation of th() seems unnecessarily complicated
8 comentarios
Hamid Iftikhar
el 18 de Sept. de 2023
William Rose
el 18 de Sept. de 2023
I am starting to understand your code more.
You make an initial guess for beta, z (collector tilt and azimuth): beta,Z=45,20.
You compute angle th(). Each element of th() corresponds to a distinct time of day.
You execute a while loop:
while th>25
% guess new beta, z;
% recompute th();
end
The expression th>25 retuns a boolean vector. The while loop executes if and only if every element of the vector is true. Therefore, if any element of th() is <=25, the statements inside the while loop will not be executed.
Sam Chak
el 19 de Sept. de 2023
I didn't make 'th' a function of beta and Z.
I might have interpreted inaccurately. Doesn't this line show the function
?
th = (180/pi*acos(FH*cos(beta*pi/180) + b.IG*sin(beta*pi/180)*cos(Z*pi/180) + b.J*sin(beta*pi/180)*sin(Z*pi/180)));
If you want to try the approach where you make a random guess for beta and Z, then you could do it by testing for the maximum value of th. See code below.
thMax=55; % maximum allowed theta (deg)
beta=45; Z=20; % collector elev, azimuth (deg) initial guess
alt=[9.7, 27.7, 35.6, 29.2, 12.1]; % Sun alt(8:00,10,noon,14,16)
Az=[124.7, 146.9, 178.1, 210.0, 233.2]; % Sun Az(8:00,10,noon,14,16)
th=acosd(sind(beta)*sind(alt)+cosd(beta)*cosd(alt).*cosd(Az-Z));
i=0; % counter
while max(th)>thMax % if max(th)>thMax, make another guess
beta=90*rand; % random (0,90)
Z=90+180*rand; % random (90,270)
th=acosd(sind(beta)*sind(alt)+cosd(beta)*cosd(alt).*cosd(Az-Z));
i=i+1;
end
fprintf('Done after %d attempts. beta=%.1f, Z=%.1f, max(th)=%.1f deg.\n',...
i,beta,Z,max(th));
Try it. Good luck!
Hamid Iftikhar
el 19 de Sept. de 2023
Hamid Iftikhar
el 19 de Sept. de 2023
Sam Chak
el 19 de Sept. de 2023
@Hamid Iftikhar, No worries. I was just trying to understand the tracking problem.
William Rose
el 19 de Sept. de 2023
@Hamid Iftikhar, you are welcome.
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

