Message Boards Message Boards

0
|
3621 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Why is this calculation list returning the same value for each iteration?

For some reason when i run this code each entry of solarcalc on columns 2 and 3 are identical. They should not be.

In[66]:= n = 344674; dayint = 5;
In[67]:= solardata = 
  Import["U:\Input.csv", "csv"];

In[68]:= date = 
  Table[DateList[{ToString[solardata[[i, 1]]], {"Month", "Day", 
      "YearShort"}}], {i, n}];

In[69]:= For[i = 1, i < n + 1, i++, 
 If[date[[i, 2]] < 11 && date[[i, 2]] > 4, date[[i, 4]] = 2, 
  date[[i, 4]] = 1]]
date[[1, 5]] = 2
For[i = 2, i < n + 1, i++, 
  If[date[[i, 3]] == date[[i - 1, 3]], 
   If[dayint == 1 || dayint == 7, date[[i, 5]] = 1, date[[i, 5]] = 2],
    If[dayint == 7, dayint = 1, dayint++];
   If[dayint == 1 || dayint == 7, date[[i, 5]] = 1, 
    date[[i, 5]] = 2]]];

Out[70]= 2

In[72]:= For[i = 1, i < n + 1, i++, 
  If[date[[i, 4]] == 1, 
   If[solardata[[i, 2]] > 8.5 && solardata[[i, 2]] < 21.5 && 
     date[[i, 5]] == 2, date[[i, 6]] = 1, date[[i, 6]] = 2], 
   If[(solardata[[i, 2]] < 9.5) || (solardata[[i, 2]] > 
       20.5) || (date[[i, 5]] == 2), date[[i, 6]] = 5, 
    If[(solardata[[i, 2]] < 20.) && (solardata[[i, 2]] > 12.), 
     date[[i, 6]] = 3, date[[i, 6]] = 4]]]];

In[73]:= (*The following line initiates the 5x5 list solar calc. Each \n    row of solar calc represents a cost period. The rows in solar calc \n    are respectively, winter partial peak, winter off peak, summer peak, \n    summer partial peak and summer off peak.*)

In[74]:= solarcalc = Table[0, {i, 5}, {j, 5}]

Out[74]= {{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0,
   0, 0}, {0, 0, 0, 0, 0}}

In[75]:= (*The following five lines count the number of minutes of \n    each cost period.*)

In[76]:= For[i = 1, i < n + 1, i++, 
 If[date[[i, 6]] == 1, solarcalc[[1, 1]]++]]

In[77]:= For[i = 1, i < n + 1, i++, 
 If[date[[i, 6]] == 2, solarcalc[[2, 1]]++]]

In[78]:= For[i = 1, i < n + 1, i++, 
 If[date[[i, 6]] == 3, solarcalc[[3, 1]]++]]

In[79]:= For[i = 1, i < n + 1, i++, 
 If[date[[i, 6]] == 4, solarcalc[[4, 1]]++]]

In[80]:= For[i = 1, i < n + 1, i++, 
 If[date[[i, 6]] == 5, solarcalc[[5, 1]]++]]

In[81]:= (*These five lines add up the total solar irradiation from \n    the Eppley on the library roof of HSU for each cost period into \n    column two of solarcalc*)

In[82]:= For[i = 1, i < n + 1, i++, 
 If[date[[i, 6]] == 1, solarcalc[[1, 2]] += solardata[[i, 3]]]]

In[83]:= For[i = 1, i < n + 1, i++, 
 If[date[[i, 6]] == 1, solarcalc[[2, 2]] += solardata[[i, 3]]]]

In[84]:= For[i = 1, i < n + 1, i++, 
 If[date[[i, 6]] == 1, solarcalc[[3, 2]] += solardata[[i, 3]]]]

In[85]:= For[i = 1, i < n + 1, i++, 
 If[date[[i, 6]] == 1, solarcalc[[4, 2]] += solardata[[i, 3]]]]

In[86]:= For[i = 1, i < n + 1, i++, 
 If[date[[i, 6]] == 1, solarcalc[[5, 2]] += solardata[[i, 3]]]]

In[87]:= (*These five lines add up the total solar irradiation from \n    the LICOR pyranometer at the landfill for each cost period into \n    column three of solarcalc*)

In[88]:= For[i = 1, i < n + 1, i++, 
 If[date[[i, 6]] == 1, solarcalc[[1, 3]] += solardata[[i, 4]]]]

In[89]:= For[i = 1, i < n + 1, i++, 
 If[date[[i, 6]] == 1, solarcalc[[2, 3]] += solardata[[i, 4]]]]

In[90]:= For[i = 1, i < n + 1, i++, 
 If[date[[i, 6]] == 1, solarcalc[[3, 3]] += solardata[[i, 4]]]]

In[91]:= For[i = 1, i < n + 1, i++, 
 If[date[[i, 6]] == 1, solarcalc[[4, 3]] += solardata[[i, 4]]]]

In[92]:= For[i = 1, i < n + 1, i++, 
 If[date[[i, 6]] == 1, solarcalc[[5, 3]] += solardata[[i, 4]]]]

In[94]:= (*The following line finds the ratio of solar radiation at \n    the landfill to that of the library roof for each cost period. These \n    ratios are entered into column four of solarcalc*)

In[95]:= For[i = 1, i < 6, i++, 
 solarcalc[[i, 4]] = solarcalc[[i, 3]]/solarcalc[[i, 2]]]

In[96]:= solarcalc

Out[96]= {{87455, 1.99405*10^7, 2.19648*10^7, 1.10152, 0}, {138074, 
  1.99405*10^7, 2.19648*10^7, 1.10152, 0}, {11486, 1.99405*10^7, 
  2.19648*10^7, 1.10152, 0}, {4217, 1.99405*10^7, 2.19648*10^7, 
  1.10152, 0}, {103442, 1.99405*10^7, 2.19648*10^7, 1.10152, 0}}
POSTED BY: Drew Clark
2 Replies

If date[[i, 6]] == 1 is True, then it will trigger solarcalc[[1, 2]] += solardata[[i, 3]] every time, for every line. That is why all position 2 are the same. Notice that for 'number of minutes' it was, date[[i, 6]] == 1 then date[[i, 6]] == 2 then date[[i, 6]] == 3 ...

I resolved the issue.

POSTED BY: Drew Clark
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract