Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Simple algebraic calculations

by Laurent_R (Canon)
on Apr 19, 2014 at 09:54 UTC ( [id://1082885]=note: print w/replies, xml ) Need Help??


in reply to Simple algebraic calculations

Half lives are used for describing the time which is takes for a quantity of radioactive substance fall to half its original value. The units are to a large extent irrelevant to the calculation itself: the same formula applies whether the original quantity is expressed in kilograms, grams, pounds, moles, etc. The same is true about durations: you only need to express the half-life and the time in the same units to get a correct result, it does not matter if this common unit is seconds or billions of years.

Given the probabilistic and exponential nature of the radioactive decay laws, you also don't really care about irregular month durations, leap years and the like. But usually, three main units are used for half-lives: seconds, days and years. You would usually not say that a given substance has a three-month half-life, because that would lack precision, but rather that its half life is, say, 90 days.

Starting from these considerations, the basic function could be as simple as that:

sub remaining { my ($start, $half, $elapsed) = @_; $remain = $start * (.5**($elapsed/half)); return $remain; }
where $start is the starting quantity (in any unit), $half the half-life and $elapsed the period duration ($half and $elapsed just have to be expressed with the same unit). The function returns the quantity of substance remaining once the period has elapsed. A sample run could be this:
print remaining (1000, 10, $_), "\n" for qw (10, 20, 30, 40); 500 250 125 62.5
which, for an initial quantity of 1000 something (grams, kilograms or whatever) and a half-life of 10 time units and periods of 10, 20, 30, 40 of the same time unit, prints the remaining quantity for each of the four time periods. So, this is quite simple. You might want to add a check that the half-life argument is not 0 (to avoid a division by zero error) and other bells and whistles, but you basically have it.

You almost never have to do time unit conversions with half-lives because of the exponential nature of the radioactive decay law. For example, if you have a half-life of one day, it makes very little sense to try to figure out what the remaining quantity is after one year, because it is so small:

print remaining (1000, 1, 365), "\n"; 1.33061245000255e-107
It is highly likely that there is not even one radioactive atom left after one year, even if your original quantity was tons of something (to give an idea of the magnitude of the numbers involved, one metric ton of for example carbon is "only" about 5e28 atoms).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1082885]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-23 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found