Fotran program to find half-life of a radioactive material

Click For Summary

Discussion Overview

The discussion revolves around writing a Fortran program to calculate the half-life of a radioactive material based on its decay constant. Participants explore programming techniques, debugging strategies, and algorithm design related to this computational problem.

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • The original poster seeks assistance with a Fortran program that calculates the time for half of a radioactive material to decay, given the decay constant.
  • One participant suggests adding PRINT statements within the loop for debugging purposes to verify the program's operation.
  • Another participant recommends incrementing a counter variable within the loop to track iterations, and suggests walking through the algorithm step by step to clarify the loop's design.
  • The original poster updates their code to successfully calculate the amount of undecayed substance after reaching half-life but expresses uncertainty about implementing a counter variable.
  • A later post provides a simple example of a counter variable in a loop, demonstrating how to increment and print its value.
  • The original poster later confirms that they resolved their issue with the program, indicating progress in their understanding.

Areas of Agreement / Disagreement

Participants generally agree on the need for debugging techniques and the importance of understanding the algorithm, but there is no consensus on the best approach to implement the counter variable initially.

Contextual Notes

The discussion includes various programming strategies and debugging methods, but does not resolve the initial uncertainties regarding the implementation of the counter variable in the loop.

Who May Find This Useful

Individuals interested in programming, particularly in Fortran, as well as those studying radioactive decay and numerical methods in physics may find this discussion beneficial.

Daniel1992
Messages
21
Reaction score
0

Homework Statement


I need to write a program that, given the decay constant of a radioactive material, will calculate numerically (to withing one second) the time taken for half of the orginal sample of material to decay.

Homework Equations


λ = decay constant C0 = start amount of material

After one second C0 will have decayed leaving C = (1-λ)C0 of undecayed material left.

The Attempt at a Solution


I only have very basic experince at programming so I am finding this quite difficult. Below is the code that I have created so far.

IMPlICIT NONE
REAL :: y,C,t !y = decay constant C = starting amount of material t = time
PRINT*,"Enter decay constant"
READ*,y
PRINT*,"Enter starting amount of material"
READ*,C

DO WHILE (C.GT.C/2)
C=(1-y)*C
END DO

PRINT*,"C=",C

I don't really have any idea how I would work out hiw many interations the DO WHILE loop has done which i need to kno in order to work out the half life.

Any help/advice would be much appreciated.
 
Physics news on Phys.org
It's helpful during the testing and debugging stage of writing a program to temporarily add a PRINT statement inside loops so that you can verify operation is exactly as you hope it will be.

Suppose you were to add a PRINT statement inside your DO loop, what useful variables would you like it to print out?

Imagine your program simulates the decay of 100 grams of material having a decay constant of 2.77 milliseconds. What are the first 6 of the output lines that your loop's added PRINT statement would print out?
 
Last edited:
You'll need a variable to act as a counter that you can increment inside the do.while loop.

Why not walk thru your algorithm step by step solving it on paper as if you were a computer?

That should make it easier to design your loop and get your answer.

What does each iteration of the do.while loop represent?
 
Thanks for the replies :)

I have managed to get the program to find the amount of undecayed substance left after the half life has been reached.

Here is the new code:
PROGRAM assignment1
IMPlICIT NONE
REAL :: y,C,t,v !y = decay constant C = starting amount of material t = time


PRINT*,"Enter decay constant"
READ*,y
PRINT*,"Enter starting amount of material"
READ*,C
v=c


DO WHILE (C.GT.v/2)
C=(1.0-y)*C
PRINT*,C
END DO

PRINT*,"C =",C
END PROGRAM assignment1


I am not sure how I can get a varibale to act as counter inside the loop.
Any help would be appreciated.
 
i=0
do while (i.lt.10)
i=i+1
print *,"i=",i
...
end do
 
Got it sorted now. Thanks for the help :smile:
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
778
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K