How to optimize the problem?

6 Ansichten (letzte 30 Tage)
Hamid Iftikhar
Hamid Iftikhar am 18 Sep. 2023
Kommentiert: William Rose am 19 Sep. 2023

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

Akzeptierte Antwort

William Rose
William Rose am 19 Sep. 2023
Bearbeitet: William Rose am 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.

Weitere Antworten (1)

William Rose
William Rose am 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 Kommentare
Sam Chak
Sam Chak am 19 Sep. 2023
@Hamid Iftikhar, No worries. I was just trying to understand the tracking problem.
William Rose
William Rose am 19 Sep. 2023
@Hamid Iftikhar, you are welcome.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by