i am new to matlab please help solving this problem
Afficher commentaires plus anciens
>> 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.
Réponses (2)
Andrei Bobrov
le 23 Oct 2017
Modifié(e) : Andrei Bobrov
le 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(:)');
1 commentaire
pabloescober
le 24 Oct 2017
Cam Salzberger
le 23 Oct 2017
1 vote
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 commentaires
pabloescober
le 24 Oct 2017
Cam Salzberger
le 24 Oct 2017
Just one line? If so, it sounds like you probably want your "radiation" variable to be a vector of the same length as "n" (i.e. 1 x 365).
What is "t" then? How does it relate to "n"? How does it relate to your radiation calculation?
pabloescober
le 24 Oct 2017
Cam Salzberger
le 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.
t = repelem(monthlyTValues, nDaysInMonth);
Again, the monthlyTValues vector will need to have the same number of values as nDaysInMonth for that to work.
-Cam
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!