From: Josef 'Jupp' SCHUGT Date: 2004-02-03T08:30:51+09:00 Subject: Re: Ruby math: Newton's Law of Cooling Hi! * Theodore Knab: > I was wondering how I would compose the following "Newton's Law of > Cooling" into a Ruby calculation: > > http://scienceworld.wolfram.com/physics/NewtonsLawofCooling.html > > t = time > T = changing temp of object > T_s = temp of surrounding environment > T_0 = initial temperature of the object > K = an experimental constant that has to do with water and surface area > > T(t) = T_s + (T_0 - T_s)e^(-Kt) Perhaps it is helpful to explain the physics behind that formula. It will be very elementary. What do we know? First of all we know that we start with some initial temperature of the object. We call it T_0. Then we know that if we wait long enough the temperature will become that of the surrounding environment. Experiments show that the temperature change is proportional to the difference between the temperature of the object and the temperature of the environment and the timespan you wait (given that the temperature does not change significantly during that timespan) So for a short timespan dt the following holds: T(t + dt) - T(t) = K * [T(t) - T(s)] * dt Now let us take a look at K. This constant describes how fast the heat exchange takes place. This depends on several factors (in no particular order): - The surface through which the exchange takes place. If the surface is large the echange is faster. - The amount of matter that has to be cooled down. Dinosaurs were de jur cold-blooded but de facto warm-blooded. - The heat capacity of the material that is cooled down. - Who likely the energy is transported away (depends on isolation, humidity of the environment, etc.) Anyway. In the limit of dt versus zero the above difference equation becomes Newtons Law of Cooling. Now let's come to the problem of how to use the equation. For this you have to assume that the temperature is the only enviromental influence that is subject to change. Otherwise things become *very* complicated. The first task is finding out K. On a day where wether is very constant so that you need not bother about a changing environment temperature you measure the temperature of the object at fixed time intervals and write down temperature and time. Now let's modifiy the equation: T(t) = T_s + (T_0 - T_s)e^(-K*t) T(t) - T_s = (T_0 - T_s) * e^(-K*t) (T(t) - T_s) / (T_0 - T_s) = e^(-K*t) ln (T(t) - T_s) - ln( T_0 - T_s) = -K*t ln (T(t) - T_s) = ln( T_0 - T_s) - K*t Let's use the abbreviations x(t) = ln (T(t) - T_s) and x_0 = ln (T_0 - T_s): x(t) = x_0 - K * t This means: If you plot x(t) on the vertical axis and t on the horizontal axis the slope is -K. Does that answer the question? Josef 'Jupp' SCHUGT -- http://oss.erdfunkstelle.de/ruby/ - German comp.lang.ruby-FAQ http://rubyforge.org/users/jupp/ - Ruby projects at Rubyforge -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Germany 2004: To boldly spy where no GESTAPO / STASI has spied before