Advertisement
luizaspan

EDO decaimento radioativo

May 12th, 2015
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. / método de euler para EDOs:
  2. // f(x+dx) = f(x) + dxF(f,x) (+ condição inicial)
  3.  
  4. // decaimento radioativo: dN/dt=-(lambda)*N
  5. // solução exata: N(t)=N(0)exp(-(lambda)*t)
  6.  
  7. #include <stdio.h>
  8.  
  9. #define dt 0.01
  10. #define lambda 0.05
  11.  
  12. int main(void)
  13. {
  14.   int i=0;
  15.   double N,t;
  16.  
  17.   N=10000;
  18.  
  19.   while (N>0.1)
  20.     {
  21.       N=N-dt*lambda*N;
  22.       t=++i*dt; // note que não foi usado i++! i++: soma 1 ao i e dá o resultado de t, ++i: dá o resultado de t e no final do loop soma 1 ao i
  23.       printf("%f\t %f\n",t,N);
  24.     }
  25.  
  26.   return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement