For loop or if condition?

Hi,
I solved system of differential equations that present temperature values in two rooms. Now, I want to apply thermostat control which is active if temperature drops below 18 or go above 20 degrees. Is this loop correct?
for i=1:t t(i)=84600; if(T(i)>=18 && T(i)<=20) go else stop end end
Or is better to use if statement?
Thanks in advance!

1 件のコメント

Nikola
Nikola 2013 年 9 月 5 日
Hi,
I defined heater function apart from function which solves system of equations. Now, I embed heater function into function with equations since I want to make responses of the heater when temperature is out of given bounds.
Can I send you code to see is it correct or suggest me what can I do to fix that?
Thanks!

サインインしてコメントする。

 採用された回答

UJJWAL
UJJWAL 2013 年 8 月 23 日

0 投票

First of all, this is not a correctly asked question.
Put your code in a correct format and be of a more explanatory nature.
While you mention 'OR' in your question , the code contains '&&' which stands for "AND".

その他の回答 (1 件)

Nikola
Nikola 2013 年 8 月 23 日

0 投票

Hi,
Thanks for quick answer. I used this procedure bu program reports some error. Yes, I know meaning of this logical operators but I didn't set question well.
So, if for loop reports error, should I use if statement instead?

6 件のコメント

UJJWAL
UJJWAL 2013 年 8 月 23 日
as I said, put the question in clear words and describe the problem very well. only then I can be of some help.
Nikola
Nikola 2013 年 8 月 23 日
Hi again,
Ok, I define system of two differential equations for two rooms in order to determine temperature function over time. Equations contain certain parameters like capacity, conductivity, heat source, etc.
I want after to solve system, to apply thermostat control, for example to bound temperature between 18 and 20 degrees. Every time when T is above 20, thermostat is off and below 18 thermostat is on.
I hope that I explained better this time, In case that you need additional information, just let me know and I will add in next post.
UJJWAL
UJJWAL 2013 年 8 月 23 日
Hello,
Since you have not given any mathematical formulation of thermostat and since I am not familiar with this subject, I will assume that something has to be done to turn off the thermostat and something else has to be done to turn it on. Consider the following piece of code and let me know if it is clear and helpful
if T>20
% Some code to turn off the thermostat
else
if T<18
% Some code to turn on the thermostat
end
Nikola
Nikola 2013 年 8 月 23 日
Hi,
Yes, I also understand what should be done about this but I need to define procedure clearly. I mostly need help about code after if statement, thus I will try tomorrow to figure out. If you know for some useful source, you can attach me here.
If I solve it or have additional question, I will write here.
Thanks in advance!
Nikola
Nikola 2013 年 8 月 27 日
Hi, I solved system and now I have to define another function called heater. Heater should be function [on,off] = heater(T1,T2) on = true; off = else; if(T1<18 (T1>= 18 && T1<=20)) heater on = 1; else if (T2<18 (T2>=18 && T2<= 20)) heater on = 1; else heater off = 1; end;
Could you check is it correct and should I make some corrections? Thanks a lot in advance!
Nikola
Nikola 2013 年 8 月 28 日
@UJJWAL Hi, I solved system and now I have to define another function called heater. Heater should be function [on,off] = heater(T1,T2) on = true; off = else; if(T1<18 (T1>= 18 && T1<=20)) heater on = 1; else if (T2<18 (T2>=18 && T2<= 20)) heater on = 1; else heater off = 1; end;
Could you check is it correct and should I make some corrections? Thanks a lot in advance!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

質問済み:

2013 年 8 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by