From: mike@... (Mike Stok) Date: 2004-02-02T02:00:01+09:00 Subject: Re: Ruby math: Newton's Law of Cooling In article <20040201142653.GA26053@annapolislinux.org>, Theodore Knab wrote: >I had a frozen pipe break in a house I was watching. Although the pipe >is now fixed and insulation was added above the pipes, the PVC >(polyvinayl choride) >water lines are still freezing. > >So, I decided I will calculate the times in which these >water lines freeze and run over and turn on the water before they freeze. > >I want to be able to calculate the time in which these water pipes >will freeze at various cold temperatures. > >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) If you just need to know how to transliterate the equation then it's relatively simple, keeping in mind the initial case of a ruby identifier matters, and that we need to use floating point rather than integers. A simple tramsliteration might be: t_s = 100.0 t_0 = 1000.0 K = 1.234 # temp at t = 0 t = 0.0 puts t_s + (t_0 - t_s) * Math.exp(-K * t) # temp at t = 1.0 t = 1.0 puts t_s + (t_0 - t_s) * Math.exp(-K * t) And this yeilds 100.0 362.013168336477 That may not be the most convenient thing to use, but you can see how the formula is converted to ruby. This should answer your question but not ruin the fun of packaging the formula into a more useful form in your program. Hope this helps, Mike -- mike@stok.co.uk | The "`Stok' disclaimers" apply. http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60 http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA