Clear Filters
Clear Filters

How to commit statement only under certain conditions?

2 views (last 30 days)
Hello, I'm simulating water heating and I need to create certain condition and I dont know how to create it properly.
Required temperature of water is 55 °C. Minimal temperature is 50 °C. Maximum temperature is 70 °C.
I have 2 types of heating - electrical heating which heats water to required temperature 55 °C and photovoltaic heating which can heat water to maximum temperature.
I need to create condition which turn on electrical heating only if temperature drops below 50 °C and stops after reaching 55 °C. If the temperature is between 50 and 55 without dropping under 50 °C only photovoltaic heating is possible and electrical heating is off.
Temperature is checked every minute for whole year. Conditions will be placed in for cycle. I dont know how to create condition for starting electrical heating under 50 and stopping at 55.
Something like that:
if temperature < 70
photovoltaic on
else
everything off
if temperature < 50
electrical heating on and stops at 55°C
Thanks for advice.

Accepted Answer

Jan
Jan on 26 Feb 2017
Edited: Jan on 26 Feb 2017
electric = true;
photovoltaic = false;
for iMinute = 1:365*24*60
if temperature(iMinute) < 50
electric = true;
elseif temperature(iMinute) > 55
electric = false;
end
photovoltaic = (temperature(iMinute) < 70);
...
end
  7 Comments
Jan
Jan on 27 Feb 2017
Edited: Jan on 27 Feb 2017
@LamaObencna: The code you have shown here, does not contain the code for changing the temperature. The part of detecting, which heating is enabled, was discussed exhaustively already, and it cannot cause the observed behavior alone. You can replace it for testing: Keep the photovoltaic and/or electric heating enabled manually and examine, what happens.
Something like "it ignores 55 °C condition" cannot happen. Matlab is not in a bad mood and ignores any line. I really want to help you and I'm convinced the problem is not included in the part of the code, which has been posted here. So please start testing the code I've suggested if it enables the heat sources exactly as you want it. Then we can proceed and find out, why the correct values do not yield the expected result in the change of the temperature.
LamaObecna
LamaObecna on 27 Feb 2017
Edited: LamaObecna on 27 Feb 2017
Done. I figured it out with help of community of stackoverflow, basicly very similar to your idea. I should show whole code, it would be easier to get it work, my mistake. Anyway, thank you for your time and advice. I have marked your answer as accepted becouse it was right direction.

Sign in to comment.

More Answers (0)

Categories

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