How to optimize the problem?

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

 Accepted Answer

William Rose
William Rose on 19 Sep 2023
Edited: William Rose on 19 Sep 2023
We know from symmetry that the best collector angle will be when the collector points south, i.e. when collector azimuth=180. Therefore I encourage you to point the collector south, and change beta (collector elevation angle).
The attached code computes the Sun's altitude and azimuth, at 10 minute intervals on the specified date, for an observer at the specified latitude and longitude. This is relatively easy, since the local hour angle is already computed in the Excel file which you supplied. The result is shown below.
The code also computes the angle θ of the Sun relative to the normal to the collector, at each time in the file, for a collector pointed south. The formula is
where β=collector elevation angle, ϕ=altitude(Sun); and =azimuth(Sun)-azimuth(collector). This formula is simply the formula for great circle distance on a unit sphere, but instead of using the latitude and longitude of two locations, I use the angles for the Sun and the collector.
The code tries six different collector elevation angles. The plot below show the results. The angle θ is a minimum at local noon, as we expect. When beta equals the Sun's maximum elevation, the angle θ is approximately zero at local noon, as we expect. The plot shows that there is no collector angle which gives at all times.

More Answers (1)

William Rose
William Rose on 18 Sep 2023
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 Comments

@William Rose I am sorry for not mentioning variables descriptions as comments. Yes you are right, vector 'th' is angle and this is incidence angle which collector normal makes with sun rays. Yes, beta and Z are tilt and surface azimuth angles and both are scalar single value inputs. I am not sure that I should use while loop for the 'th' expression as I didn't make 'th' a function of beta and Z. What possible constraint for 'th' can we use instead of th<10 ? Thank You.
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.
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));
Done after 450 attempts. beta=29.2, Z=179.8, max(th)=55.0 deg.
Try it. Good luck!
Thank you so much for enormous support. I highly appreciate you for looking into the issue and providing valuable solution.
I am not sure as we can not use some commands of function unless we write the equation as @(beta) something. I hope you agree.
@Hamid Iftikhar, No worries. I was just trying to understand the tracking problem.
@Hamid Iftikhar, you are welcome.

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!