User and GPT Code
User and GPT Code
clear; clc;
format short;
%% USER INPUT
n = input('Enter day of the year (1 to 365): ');
phi = input('Enter the latitude of the location (in degrees): ');
LL = input('Enter the longitude of the location (in degrees): ');
beta = input('Enter tilt angle of collector (in degrees): ');
gamma = input('Enter azimuth angle of collector (in degrees): ');
hours = 0:23;
omega = zeros(1, 24);
cos_theta = zeros(1, 24);
alpha_s = zeros(1, 24);
theta_z = zeros(1, 24);
m = zeros(1, 24);
A = zeros(1, 24);
k = zeros(1, 24);
IB = zeros(1, 24);
IBC = zeros(1, 24);
IDC = zeros(1, 24);
IRC = zeros(1, 24);
IC = zeros(1, 24);
for h = 1:24
ST = hours(h) + ST_LT;
omega(h) = deg2rad((ST - 12) * 15);
cos_theta(h) = sin(delta)*sin(phi)*cos(beta) ...
- sin(delta)*cos(phi)*sin(beta)*cos(gamma) ...
+ cos(delta)*cos(phi)*cos(beta)*cos(omega(h)) ...
+ cos(delta)*sin(phi)*sin(beta)*cos(gamma)*cos(omega(h));
cos_theta(h) = max(min(cos_theta(h), 1), -1);
alpha_s(h) = asin(cos(phi)*cos(delta)*cos(omega(h)) + sin(phi)*sin(delta));
theta_z(h) = acos(cos(phi)*cos(delta)*cos(omega(h)) + sin(phi)*sin(delta));
if alpha_s(h) > 0
m(h) = 1 / (sin(alpha_s(h)) + 0.50572 * (6.07995 + rad2deg(alpha_s(h)))^(-1.6364));
else
m(h) = Inf;
end
A(h) = 1160 + 75 * sin(deg2rad((360/365)*(n - 275)));
k(h) = 0.174 + 0.035 * sin(deg2rad((360/365)*(n - 100)));
IB(h) = A(h) * exp(-k(h) * m(h));
IBC(h) = IB(h) * cos_theta(h);
if IBC(h) < 0
IBC(h) = 0;
end
C = 0.095 + 0.04 * sin(deg2rad((360/365)*(n - 100)));
IDC(h) = C * IB(h) * (1 + cos(beta)) / 2;
IRC(h) = rho * IB(h) * (sin(alpha_s(h)) + C) * (1 - cos(beta)) / 2;
IC(h) = IBC(h) + IDC(h) + IRC(h);
end
figure;
plot(hours, IC, 'r-', 'LineWidth', 2);
xlabel('Hour of Day');
ylabel('Total Radiation on Collector (W/m^2)');
title(['Total Solar Radiation on Flat Plate Collector (Day ' num2str(n) ')']);
grid on;