U235와 같은 불안정한 원소의 경우 비교적 빠른 시간안에 붕괴함을 볼 수있다.
그것에 관한 식을 살펴보자.
(1/N)(dN/dt)=-1/tau
위의 식에서 그 해를 찾는다면
N(t) = N0)exp(-t/tau)로 나타낼 수 있고
Taylor Expansion을 통해 유효한 항 까지 취한다면
N(t+Δt) = N(t)+(dN/dt) = N(t) - (N/tau)
의 꼴이 된다.
이 식을 바탕으로 c 언어를 사용해 프로그래밍을 해보면 소스코드는 다음과 같다
/* radioactivedecay.c
* Simulation of radioactive decay
*/
#include <stdio.h>
#include <math.h>
#define MAX 100
int main(void)
{
double n[MAX];
double t[MAX];
double dt;
double tau;
int i;
int j;
FILE *fp_out;
printf("initial number of nuclei->");
scanf("%lf",&(n[0]));
t[0]=0.0;
printf("time constant->");
scanf("%lf",&tau);
printf("time step->");
scanf("%lf",&dt);
for(i=0; i< MAX-1; i++)
{
n[i+1]=n[i]-(n[i]/tau)*dt;
t[i+1]=t[i]+dt;
}
fp_out=fopen("decay.dat","w");
for(j=0; j<MAX; j++)
{
fprintf(fp_out, "%g\t%g\n", t[j], n[j]);
}
fclose(fp_out);
return 0;
}