i am new to matlab please help solving this problem

>> 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)

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 Comment

thank you... it helps although i did not get my coorect graph

Sign in to comment.

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

i need to plot a graph i.e radiation vs n if that make sense to your question...
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?
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?
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

Asked:

on 23 Oct 2017

Commented:

on 24 Oct 2017

Community Treasure Hunt

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

Start Hunting!