How to use while loop in this condition?

I have an equation QR = Qs + Qj(T) - Qr(T) - Qc(T) a temperature is supposed like T =25 Now there are two conditions: When QR > 0, T = T+1 When QR < 0, T = T-1 And the New value of T is put into the equation. When QR = 0, the iteration stops and the assumed value of T becomes final How to write the code for this? Please Explain. For finding QR, there are a set of equations where T is a variable. So whether I should write the set of equations inside the while loop or outside it because the loop is going to solve the equation in each step until the term QR becomes zero. PLEASE explain me in a bit detail.
THANKS for the answers but there is some problem. It is not working

2 comentarios

KALYAN ACHARJYA
KALYAN ACHARJYA el 10 de Abr. de 2018
There is no T in the equation, here Qj, Qr and Qc are functions of T.
Walter Roberson
Walter Roberson el 10 de Abr. de 2018
In any situation like this there is the possibility of infinite oscillator. Suppose at 17 the value is -1e-9 and at 16 the value is +3e-10. The algorithm would require that you go between the two values until the heat death of the universe made everything 0.

Iniciar sesión para comentar.

Respuestas (2)

Birdman
Birdman el 10 de Abr. de 2018
Editada: Birdman el 10 de Abr. de 2018
One approach:
%code
while true
if QR>0
T=T+1;
elseif QR<0
T=T-1;
else
break;
end
%update your function here
end
%code
Since T value is updated at every step in while loop, you don't need to do anything extra. Also, this is just a template. Add your code to necessary places.
KSSV
KSSV el 10 de Abr. de 2018
Editada: KSSV el 10 de Abr. de 2018
% define all data required.
while QR~=0
if QR<0
T = T-1 ;
elseif QR > 0
T = T+1 ;
end
QR = Qs + Qj(T) - Qr(T) - Qc(T) ;
end

1 comentario

KALYAN ACHARJYA
KALYAN ACHARJYA el 10 de Abr. de 2018
Editada: KALYAN ACHARJYA el 10 de Abr. de 2018
@KSSV Sir I have one confusion, How T is updated in QR?

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 10 de Abr. de 2018

Editada:

el 10 de Abr. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by