My code for simulating a batterylevel-state throughout a year in 15min-steps doesn't work.
There is a certain list-inputs which simulates the charge state and the batterylevel-state, additionally maximum capacity and minimum capacity(because of discharge-depth) and L as start charging state
maxk=10;
mink=2;
L=5;
chargelevel= {-0.1,-0.1,-0.2, ...(more than 35000 other positive/negative values)...,-0.2,-0.1};
batterylevel=Table[L, {n, 0, 35040}]
which is used by
For[i = 1, i < 35040, i++,
Which[mink <= (batterylevel[[i - 1]] + chargelevel[[i]]) <= maxk,
batterylevel[[i]] = (batterylevel[[i - 1]] + chargelevel[[i]]),
batterylevel[[i]] <= mink, batterylevel[[i - 1]] = mink,
batterylevel[[i]] >= maxk, batterylevel[[i - 1]] = maxk
];];
ListPlot[batterylevel]
batterylevel`
The function should be working like this:
The loop defines that i is running over the whole thing 35040 times and the batterylevel from step i-1
should be summed up with the chargelevel from step i
.
If the charge state reaches or falls below 2kWh
, it should stay at mink=2kWh
and don't add negative chargelevel-rates anymore and go on with looping until there is a positive chargelevel, then it should add chargerates again and load the battery until maxk=10kWh
and then stop again at 10kWh
and go on with looping. When it reaches negative states, it should discharge again until 2
and so on.
So far i successfully modeled this thing in excel and it worked flawlessly. The crazy thing is that it worked yesterday after trying it a few times and it matched with the result in excel.
Today since i loaded the same notebook (!) it doesn't give me the same output anymore because according to the batterylevel-output it discharges till or below 2
(since it's more likely to reach mink=2
first) and then it starts at L=5
again, adding or substracting the rates according to the chargelevel. The same happens when reaching maxk=10
, it just jumps back to L=5
. It doesn't jump with the chargelevel-list though.
According to PlotList
it looks like this, where you can clearly see that it jumps back:
I even tried to rewrite the loop with while and the conditional with If and Switch, where i get the same result (although If is made like the one in Excel).
Can somebody help me out with this please?