iteration - iterative solution python (finding the last and second last iterative values) -


i total beginner in programming , have write short code in python. finding iterative solution variable when difference between successive iterations no more 0.0001.

i thought of using infinite while loop how can check values obtained after second last , last iteration specify break condition.

please can explain how that?

here code i've written

icl=0.5 tc= 25  def kelvin(tc):     tk = tc +273.15     return tk  #calculate initial value tcl  tcl=kelvin(tc)+(35.5-tc)/(3.5*icl+0.1)  #calculate final value of tcl when difference between successive values of tcl <0.0001  while true:     tcl=35.7-0.028*(m-icl)*(3.96e-8*fcl((tcl+273.15)**4-(tr+273.15)**4+fcl*hc*(tcl-ta))      if .... #here not sure how break loop when above mentioned condition met 

in code, store tcl need store tcl , previous_tcl. @ minimum, can modify code way:

cl=0.5 tc= 25 def kelvin(tc): tk = tc +273.15 return tk  #calculate initial values tcl , tcl_previous tcl_previous = kelvin(tc)+(35.5-tc)/(3.5*icl+0.1) tcl = 35.7-0.028*(m-icl)*(3.96e-8*fcl((tcl_previous+273.15)**4-(tr+273.15)**4+fclhc(tcl_previous-ta))  #calculate final value of tcl when difference between successive values of tcl <0.0001  while math.abs(tcl-tcl_previous)>0.0001:     tcl_previous = tcl     tcl = 35.7-0.028*(m-icl)*(3.96e-8*fcl((tcl_previous +273.15)**4-(tr+273.15)**4+fclhc(tcl_previous -ta)) 

note not cleanner way write because line calculates tcl tcl_previous duplicated. should encapsulate in function.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -