i am new to matlab please help solving this problem

9 views (last 30 days)
>> n=1:1:365;
>> I=1.367;
>> d=23.45.*sin(360.*(284+n)./365);
>> t=[43.69 34.47 22.17 7.39 2.74 5.74 14.43 26.38 37.93 46.62 49.62];
>> radiation=I.*(1+0.033.*cos((360.*n)./365)).*cos(t);
Error using .*
Matrix dimensions must agree.

Answers (2)

Andrei Bobrov
Andrei Bobrov on 23 Oct 2017
Edited: Andrei Bobrov on 23 Oct 2017
May be so?:
n=1:1:365;
I=1.367;
d=23.45*sin(360*(284+n(:))/365);
t=[43.69 34.47 22.17 7.39 2.74 5.74 14.43 26.38 37.93 46.62 49.62];
radiation = I*(1+0.033*cos(360*n(:)/365))*cos(t(:)');

Cam Salzberger
Cam Salzberger on 23 Oct 2017
Hello Besii,
You are trying to do element-wise operations between a 1x365 vector and a 1x11 vector. The dimensions of those arrays do not match, so it can't do the operation.
What exactly do you expect "radiation" to be? Did you want a scalar output, a matrix, a vector the same size as "n", or a vector the same size as "t"?
-Cam
  4 Comments
pabloescober
pabloescober on 24 Oct 2017
n=no. of days i.e 365 t=zenith angle per month(i.e the given t value are value per month) is it possible to plot a graph?
Cam Salzberger
Cam Salzberger on 24 Oct 2017
Alright, so now it makes a little more sense. In this case, you want to determine the t value for each day before you use this in your calculation for radiation. You need t to be the same size as n.
One way to do it would be to loop through the months and replicate the number to form your t vector. It's not the most efficient, but it works:
monthlyTValues = [43.69 34.47 22.17 7.39 2.74 5.74 14.43 26.38 37.93 46.62 49.62];
nDaysInMonth = [31 28 31 30 31 30 31 31 30 31 30 31];
t = zeros(1, 365);
dayIdx = 1;
for monthIdx = 1:numel(monthlyTValues)
t(dayIdx:dayIdx+nDaysInMonth(monthIdx)-1) = monthlyTValues(monthIdx);
dayIdx = dayIdx+nDaysInMonth(monthIdx);
end
Or, rather, it would work if you had a zenith angle for every month in the year. I'm assuming you're missing a data point? I'll let you determine which month is missing, and fill that in.
A better way in R2015a or later is to use the repelem function.
t = repelem(monthlyTValues, nDaysInMonth);
Again, the monthlyTValues vector will need to have the same number of values as nDaysInMonth for that to work.
-Cam

Sign in to comment.

Categories

Find more on Mathematics 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!