0

Hello , I am trying to solve some problems from the "Computer Simulation Methods" book.

It says

Write a class that solves the nuclear decay problem.Input the decay constant l from the control window.For l=1 and dt=0.01 ,compute the difference between the analytical result and the result of the euler algorithm for Nt/N0 at t=1 and t=2.Assume that time is measured in seconds.

(The above is for java ,but I want to do it in c++).

My question is how I will implement Euler algorithm.

I know ,that in motion for example , the Euler algorithm goes as :

```
void Euler(){
x=x0+v0*dt;
v=v0-k*x0*dt;
t=t+dt;
error = fabs((x0-analyticPosition(1,0.01))/x0);
v0=v;
x0=x;
}
```

where x is the position ,v is velocity and xo,vo are initial values.

I can't understand in the decay situation where Nt/N0=exp(-l) how should I implement Euler.

Thanks!

*Edited 3 Years Ago by glao*