Here's some sample code that calculates the half-life of a radioactive isotope using matlab:
main.m411 chars15 lines
In this code, we first define the decay constant lambda and initial amount N0 of the isotope. We then define a time range t over which to calculate the corresponding amounts of the isotope (using the exponential decay equation).
Next, we find the time (in t) at which the amount of the isotope has halved by finding the minimum absolute difference between the calculated amounts (Nt) and half the initial amount (N0/2). Finally, we output the calculated half-life.
gistlibby LogSnag