Reputation: 384
I'm very new in modeling systems. With a friend's help, We created this model in R
hours <- seq(6+20/60, 18+31/60, 0.01)
h_radians <- (pi/12) * (hours - (12+26/60))
doy <- 268
decl_radians <- 23.45 * sin(2*pi*(284+doy)/365) * pi / 180
lat_radians <- 23.45 * pi / 180
sin_gamma <- sin(lat_radians)*sin(decl_radians) + cos(lat_radians)*cos(decl_radians)*cos(h_radians)
m <- 1/sin_gamma
irradiance[is.na(irradiance)] <- 0
irradiance <- 1353 * sin_gamma * 0.687 ^ (m ^ 0.678)
the output is like that;
When I try to move this mathematical model to simulink, cannot do it. That is what I tried to do
Actually, I cant imagine how the time is used in Simulink. Would you help me to fix my issue ?
Upvotes: 0
Views: 191
Reputation: 41220
You could simply use a Matlab function block to make the calculation exactly as you did it in R:
function irr = irradiance(h,day,lat)
h_radians = (pi/12) * (h - (12+26/60));
decl_radians = lat * sin(2*pi*(284+day)/365) * pi / 180;
lat_radians = lat * pi / 180;
sin_gamma = sin(lat_radians)*sin(decl_radians) + cos(lat_radians)*cos(decl_radians)*cos(h_radians);
m = 1./sin_gamma;
pow = m .^ 0.678;
pow(imag(pow)~=0)=NaN;
irr = 1353 .* sin_gamma .* 0.687 .^pow;
end
Then you should configure the solver to define simulation duration / step :
The simulation will run 12 hours with a step of 0.01 hour.
As you want to simulate between 6h and 18h, I added 6 hours to the simulation clock block.
Without surprise, the result is similar to what you got in R : Simulink can also "model the sun"!
Upvotes: 1