From: ts Date: 2004-02-02T00:14:14+09:00 Subject: Re: Ruby math: Newton's Law of Cooling >>>>> "T" == Theodore Knab writes: T> http://scienceworld.wolfram.com/physics/NewtonsLawofCooling.html T> t = time T> T = changing temp of object T> T_s = temp of surrounding environment T> T_0 = initial temperature of the object T> K = an experimental constant that has to do with water and surface area T> T(t) = T_s + (T_0 - T_s)e^(-Kt) well, the problem is that K is an experimental constant and must be computed. To compute it, you must know the value of T at 2 differents times, say t0 and t1. This will give you the relation given in (7) K = 1/t1 * ln((T0 - Ts) /(T1 -Ts)) then to find the time needed to reach T2, you have the equation (8) t2 = t1 * (ln((T0 - Ts)/(T2 - Ts))/ln((T0 - Ts)/(T1 - Ts))) which translated in ruby is just t2 = t1 * (Math::log((T0 - Ts)/(T2 - Ts))/Math::log((T0 - Ts)/(T1 - Ts))) this give something like this svg% cat b.rb #!/usr/bin/ruby T0 = 12.0 # initial temperature Ts = -6.0 # surrounding temperature T1 = 6.0 # temperature after 60s D1 = 60.0 # time to reach T1 def reach(t) D1 * Math::log((T0 - Ts)/(t - Ts)) / Math::log((T0 - Ts)/(T1 - Ts)) end p reach(6) # time to reach 6 (it must give D1) p reach(0) # time to reach 0 svg% svg% b.rb 60.0 162.570677481087 svg% Guy Decoux