Professional Web Applications Themes

Ruby math: Newton's Law of Cooling - Ruby

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 ...

  1. #1

    Default Ruby math: Newton's Law of Cooling

    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)


    P.S.
    I have a BA in a humanities discipline :-(


    --
    ------------------------------------------
    Ted Knab
    Chester, MD 21619
    ------------------------------------------
    35570707f6274702478656021626f6c6964796f6e602f66602 478656
    02e6164796f6e60237471647560216e6460276c6f62616c602 57e696
    4797e2a0


    Theodore Guest

  2. #2

    Default Re: Ruby math: Newton's Law of Cooling

    >>>>> "T" == Theodore Knab <org> 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


    ts Guest

  3. #3

    Default Re: Ruby math: Newton's Law of Cooling

    In article <org>,
    Theodore Knab <org> wrote: 

    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
    --
    co.uk | The "`Stok' disclaimers" apply.
    http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA
    com | Fingerprint 0570 71CD 6790 7C28 3D60
    http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA
    Mike Guest

  4. #4

    Default Re: Ruby math: Newton's Law of Cooling

    Hi!

    * Theodore Knab: 

    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


    Josef Guest

  5. #5

    Default Re: Ruby math: Newton's Law of Cooling

    On Sun, Feb 01, 2004 at 11:26:56PM +0900, Theodore Knab wrote: 
    Hi

    I fear your won't get very good results with this formula. I only tells you
    at which time the water in the pipes will reach 0 degrees celcius (sorry,
    don't know what this is is farenheit). But even after reaching 0 degrees, it
    will take quite a time until the water starts to freeze - the water has to
    loose a lot of energy to it's environment to get from the liquid state into
    crystaline state.

    greetings, Florian Pflug


    Florian Guest

  6. #6

    Default Re: Ruby math: Newton's Law of Cooling

    Hi!

    * Florian G. Pflug:
     

    0 degree Celsius is 0 degree centigrade is 32 degree Fahrenheit is
    273.15 Kelvin (sometimes mistermed 'degree Kelvin' even though it is
    *no* degree scale)
     

    To give numbers the specific melting enthalpie of H20 is 334 kJ/kg.
    Note that impurities like HCl can change the melting temperature of
    water by several Kelvin.

    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


    Josef Guest

Similar Threads

  1. math problem will Math.floor help
    By javman webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 5
    Last Post: February 4th, 01:28 AM
  2. Replies: 10
    Last Post: January 29th, 08:58 PM
  3. Replies: 4
    Last Post: December 19th, 07:09 AM
  4. Powerbook cooling failure
    By Lars Farm in forum Mac Portable
    Replies: 5
    Last Post: September 17th, 04:48 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139