How to create a loop for the following problem in MATLAB?

1 visualización (últimos 30 días)
WASIM ASHRAF
WASIM ASHRAF el 27 de Jul. de 2021
Respondida: Prateek Rai el 30 de Jul. de 2021
% OBJECTIVE: To determine total radiation (I_t) for a whole year.
% Here n is no of day of the year. Here n is varying from fisrt day to last day of a year.
% According to this n variation a loop formation is required.
n = 1 : 1 : 365;
% FOR the months of year from ASHRAE-1972 MODEL
% A,B,C are Variables and depend on month value. Each value corresponds to a perticular month.
A = [1202 1187 1164 1130 1106 1092 1093 1107 1136 1136 1190 1204];
B = [0.141 0.142 0.149 0.164 0.177 0.185 0.186 0.182 0.165 0.152 0.144 0.141];
C = [0.103 0.104 0.109 0.120 0.130 0.137 0.138 0.134 0.121 0.111 0.106 0.103];
B_1 = (360/365)*(284+n);
EOT = 9.87*sind(2*B_1) - 7.53*cosd(B_1) - 1.5*sind(B_1);
LON = 87.23; % Longitude
LSM = 82.58; % Local Standard Meridien
LStT = 14.0; % 2 PM
LST = LStT + EOT/60 + 4*(LON - LSM)/60;
Hour_angle = 15*(LST-12);
phi = 22.35; % Latitude
beta = 20; % tilt angle
gama = 15; % Surface azimuth angle
delta = 23.45*sind((360/365)*(284+n));
omega_s = acosd(-tand(phi)*tand(delta));
alpha_s = asind(cosd(phi)*cosd(delta)*cosd(Hour_angle) + sind(phi)*sind(delta));
theta_z = 90 - alpha_s;
theta_1 = acosd((sind(delta)*sind(phi)*cosd(beta) + cosd(delta)*cosd(Hour_angle)*cosd(phi)*cosd(beta) + cos(delta)*cosd(Hour_angle)*cosd(gama)*sind(phi)*sind(beta) + cosd(delta)*sind(beta)*sind(gama)*sind(Hour_angle) - sind(delta)*sind(beta)*cosd(phi)*cosd(gama)));
theta = theta_1 - 90;
I_bn = A*exp(-B/cosd(theta_z));
I_b = I_bn*cosd(theta_z);
I_d = C*I_bn;
r_b = cosd(theta)/(sind(delta)*sind(phi)+cosd(delta)*cosd(Hour_angle)*cosd(phi));
rho= 0.2;
r_r = rho*(1-cosd(beta))/2;
r_d = (1+cosd(beta))/2;
I_t = I_b*r_b + I_d*r_d + (I_b+I_d)*r_r;
  3 comentarios
WASIM ASHRAF
WASIM ASHRAF el 28 de Jul. de 2021
@Ankit I'm facing to create a for loop for this, because my n value varying from 1 to 365 but A, B and C are different for different months. How to create loops for these?

Iniciar sesión para comentar.

Respuestas (1)

Prateek Rai
Prateek Rai el 30 de Jul. de 2021
To my understanding, you want to create a “for” loop where your “n” value is varying from 1 to 365 (representing day of a year) and “A”, “B” and “C” are changing depending on the month.
I have created a “for” loop for your problem.
Note: Comments enclosed within % -- … --% represent my comments for the modification.
Here is the code for your assistance:
% OBJECTIVE: To determine total radiation (I_t) for a whole year.
% Here n is no of day of the year. Here n is varying from fisrt day to last day of a year.
% According to this n variation a loop formation is required.
% -- Here using for loop -- %
for n = 1 : 1 : 365
% FOR the months of year from ASHRAE-1972 MODEL
% A,B,C are Variables and depend on month value. Each value corresponds to a perticular month.
% -- Replacing A with A_month, B with B_month, C with C_month -- %
A_month = [1202 1187 1164 1130 1106 1092 1093 1107 1136 1136 1190 1204];
B_month = [0.141 0.142 0.149 0.164 0.177 0.185 0.186 0.182 0.165 0.152 0.144 0.141];
C_month = [0.103 0.104 0.109 0.120 0.130 0.137 0.138 0.134 0.121 0.111 0.106 0.103];
% -- Choosing A, B and C as per month -- %
month_index = 0;
if n >= 1 && n <=31 % Jan
month_index = 1;
elseif n>=32 && n<=59 % Feb
month_index = 2;
elseif n >= 60 && n <=90 % Mar
month_index = 3;
elseif n >= 90 && n <=120 % Apr
month_index = 4;
elseif n >= 121 && n <=151 % May
month_index = 5;
elseif n >= 151 && n <=181 % Jun
month_index = 6;
elseif n >= 182 && n <=212 % Jul
month_index = 7;
elseif n >= 212 && n <=243 % Aug
month_index = 8;
elseif n >= 243 && n <=273 % Sep
month_index = 9;
elseif n >= 273 && n <=304 % Oct
month_index = 10;
elseif n >= 304 && n <=334 % Nov
month_index = 11;
elseif n >= 334 && n <=365 % Dec
month_index = 12;
end
A = A_month(month_index);
B = B_month(month_index);
C = C_month(month_index);
B_1 = (360/365)*(284+n);
EOT = 9.87*sind(2*B_1) - 7.53*cosd(B_1) - 1.5*sind(B_1);
LON = 87.23; % Longitude
LSM = 82.58; % Local Standard Meridien
LStT = 14.0; % 2 PM
LST = LStT + EOT/60 + 4*(LON - LSM)/60;
Hour_angle = 15*(LST-12);
phi = 22.35; % Latitude
beta = 20; % tilt angle
gama = 15; % Surface azimuth angle
delta = 23.45*sind((360/365)*(284+n));
omega_s = acosd(-tand(phi)*tand(delta));
alpha_s = asind(cosd(phi)*cosd(delta)*cosd(Hour_angle) + sind(phi)*sind(delta));
theta_z = 90 - alpha_s;
theta_1 = acosd((sind(delta)*sind(phi)*cosd(beta) + cosd(delta)*cosd(Hour_angle)*cosd(phi)*cosd(beta) + cos(delta)*cosd(Hour_angle)*cosd(gama)*sind(phi)*sind(beta) + cosd(delta)*sind(beta)*sind(gama)*sind(Hour_angle) - sind(delta)*sind(beta)*cosd(phi)*cosd(gama)));
theta = theta_1 - 90;
I_bn = A*exp(-B/cosd(theta_z));
I_b = I_bn*cosd(theta_z);
I_d = C*I_bn;
r_b = cosd(theta)/(sind(delta)*sind(phi)+cosd(delta)*cosd(Hour_angle)*cosd(phi));
rho= 0.2;
r_r = rho*(1-cosd(beta))/2;
r_d = (1+cosd(beta))/2;
I_t = I_b*r_b + I_d*r_d + (I_b+I_d)*r_r;
end

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by